Mostly quantum mechanics. The fact that an electron can only exist at certain distances from the nucleus has to do with its wave properties. It's similar to how there is a minimum frequency that a guitar string can vibrate at due to its length, tension, and mass. Due to the forces and energies involved, there is a minimum distance that an electron can exist from a nucleus.
However, sometimes that minimum distance lies inside the nucleus. The element mercury (among others) can capture one of its own inner electrons. A proton reacts with the electron to form a neutron and a neutrino. Mercury minus one proton is gold.