The direct answer is this:
Electrons have a ground state. Collapsing into the nucleus would require more energy, not less.
To understand, think about gravity and how rocks fall until they hit the ground. To dig into the ground requires more energy. An electron at ground state is akin to a rock resting on the ground — the electron’s lowest permitted energy state. Atoms have a floor not all that different from the ground you and I stand on; both are akin to two repelling magnets.
To be a bit more precise, electrons have potential energy, and they can lose or gain energy but their lowest permitted energy state is its ground state. That much we know. Heck, we don’t yet know if they are more like a rock, wave, or a vibrating string! But they have no lower energy state than their ground state.
That means electrons can reach that “low” an energy state, and no “lower.” Squeezing an electron into a smaller region raises its kinetic energy, so eventually getting closer would require more total energy, not less.
When an electron gains enough energy, it jumps to a higher energy state. Think “farther” away from the nucleus, generally speaking. That’s what Bohr was trying to explain with his familiar flat model of the atom. He later regretted it when science revealed a more complicated picture. Today, science gives us a more accurate cloudy picture: the electron probability cloud.
Why does nature give electrons a ground state in the first place? That’s a deeper, still-open question.