
The overall reason for the electronic energy to be negative is because they are in a bound state. Only at the unbounded state, the electronic energy is either zero. So, when these electrons are brought closer, their energy scale becomes negative as there is maximum forces of attaction/repulsion while coming close.
Let us understand in a bit detail.
Consider an electron and the nucleus of an atom. They attract each other due to their opposite charge. As a result of this attraction the electron has potential energy, Ep.
As the electron moves away from the nucleus, this potential energy increases (in the same way as the potential energy of a stone increases as it moves away from the surface of the Earth). However, as the electron moves away from the nucleus, the increased distance makes the force due to the electrical attraction smaller. At infinity, the attraction between the two is zero.No attraction means the potential energy is also zero.
So at the biggest distance from the nucleus, where you would logically expect to have the biggest value of potential energy, you find that the Ep value is in fact zero. That means that the biggest value possible is zero. Therefore, as you move back towards the nucleus and lose potential energy, you must be going below zero potential energy, i.e. you must have negative potential energy.
For this reason, all the electron energy levels in diagrams are given a negative value, showing that the potential energy at that point is less than it is at infinity.