The energy levels of protons and electrons were extremely high in the early universe, which was close to 380,000 years after Big Bang. With the expansion and cooling, they gradually decreased to the point where electrons, protons, electrons, and helium nuclei were able to come together by radiating photos and more often than others staying together. Even if an electron joined with a proton there was enough electromagnetic energy to make the atom ionized quickly.
These particles had to first lose some energy in order to make atoms. This was also true hundreds of thousands of years later, when more massive elements formed in stars or during supernova explosions. To form heavier atoms, the electrons and nuclei that they joined had to lose energy.
Classical electrodynamics predicted that any accelerating charged particle would radiate electromagnetic energy continuously. This would be impossible for particles that move at constant speeds along straight lines. However, electrons in atoms do not move in straight lines.
Quantum mechanics was created in part to explain how electrons don’t lose more energy and spiral into nuclei. The simplest explanation is that electrons can only have a certain amount of energy within an atom. Once it reaches this low energy, no electron can lose any more energy. There are limits on how many electrons an atom can contain. For example, atoms that have a lot protons or electrons, only two electrons can be at the lowest level of energy and eight at the highest.
The electrons in atoms don’t orbit nuclei. This would suggest that electrons can travel around nuclei in a certain way, which is inconsistent with the Uncertainty Principle. This is why “orbital” has been replaced by “orbit”.
The fundamental answer is that electrons have a lot of potential energy and kinetic energy relative to nuclei, before they form atoms. There are also limits on how much they can lose.