It is always good to remember the historical context. The statement
An element whose atoms have no electrons outside filled energy levels is particularly stable chemically. Such elements are called noble gases.
confuses the phenomenon with the conclusion. The story was the following:
- Mendeleev knew nothing about the group of stable elements in 1869, the Nobel gases were simply not discovered at that time.
- The discovery of the noble gases aided in the development of a general understanding of atomic structure. In 1895, French chemist Henri Moissan attempted to form a reaction between fluorine, the most electronegative element, and argon, but failed. Learning from these experiments, Danish physicist Niels Bohr proposed in 1913 that the electrons in atoms are arranged in shells surrounding the nucleus, and that for all noble gases except helium the outermost shell always contains eight electrons.
- In 1916, Gilbert N. Lewis formulated the octet rule, which concluded an octet of electrons in the outer shell was the most stable arrangement for any atom; this arrangement caused them to be unreactive with other elements since they did not require any more electrons to complete their outer shell.
(Point 2 and 3 are quotes from Wikipedia about Nobel gases)
=> It was and is until today a empirical fact, that elements with 2, 8 and again 8 electrons fill shells in a way, that these shells are particularly stable chemically.
Stable chemical compounds formed from atoms whose valence add up to zero. What is so special about both atoms having noble gas configuration?
Let us remember the historical context again:
- The (Bohr’s) model's key success lay in explaining the Rydberg formula for the spectral emission lines of atomic hydrogen. While the Rydberg formula had been known experimentally, it did not gain a theoretical underpinning until the Bohr model was introduced.
- The electron is able to revolve in certain stable orbits around the nucleus without radiating any energy contrary to what classical electromagnetism suggests.
- The Bohr model gives almost exact results only for a system where two charged points orbit each other at speeds much less than that of light. This involves one-electron systems such as the hydrogen atom, singly ionized helium, and doubly ionized lithium.
- Several enhancements to the Bohr model were proposed, most notably the Sommerfeld model or Bohr–Sommerfeld model, which suggested that electrons travel in elliptical orbits around a nucleus instead of the Bohr model's circular orbits.
- In the end, the model was replaced by the modern quantum mechanical treatment of the hydrogen atom, which was first given by Wolfgang Pauli in 1925, using Heisenberg's matrix mechanics. The current picture of the hydrogen atom is based on the atomic orbitals of wave mechanics which Erwin Schrödinger developed in 1926.
(All points are quotes from Wikipedia about Bohr model)
In a nutshell (again from Wikipedia):
- The emission spectra of excited electrons in atoms are the experimental facts.
- Bohr's condition, that the angular momentum is an integer multiple of ħ ...
- ... was later reinterpreted in 1924 by de Broglie as a standing wave condition: the electron is described by a wave and a whole number of wavelengths must fit along the circumference of the electron's orbit.
- In modern quantum mechanics, the electron in hydrogen is a spherical cloud of probability that grows denser near the nucleus. The rate-constant of probability-decay in hydrogen is equal to the inverse of the Bohr radius
=> All explanations and conclusions are based on the chemical stability of Nobel gases. There is no explanation why Nobel gas atoms have 2, 8 and again 8 electrons in a stable arrangement; except for the fact that there are solutions for partial differential equations which can describe the electron excitations.
Quantum mechanics solves such partial differential equations for the spherical probability for electrons by the help of spherical harmonics.
Despite their name, spherical harmonics take their simplest form in Cartesian coordinates. This leads to spherical probabilities with 2 electrons for the s-shell and 6 electrons in the p-shell

But spherical harmonics have also another solutions. More general spherical harmonics of degree ℓ are not necessarily those of the Laplace basis $Y_{\ell }^{m}$, and their nodal sets can be of a fairly general kind. (Wikipedia)
One solution correspondent with the cubical atom, proposed by Lewis:
The cubical atom was an early atomic model in which electrons were positioned at the eight corners of a cube in a non-polar atom or molecule. This theory was developed in 1902 by Gilbert N. Lewis and published in 1916 in the article "The Atom and the Molecule" and used to account for the phenomenon of valency... The figure below shows structural representations for elements of the second row of the periodic table.

The corresponding spherical harmonics is the following:

Each of the eight segments of the sphere topologically corresponds to the eight edges of a cube.
Up to this point, I have only described what science says. Since your question didn't receive enough attention, I feel free to add my own thoughts to tell you why 2 and 8 electrons in a shell are perfect balanced around a nucleus.
Based on Lewis cubical distribution of electrons and remembering, that electrons have a magnetic dipole moment, it is possibly to bring the eight outer electrons of Ne and Ar into a perfect equilibration. This is the case for 4 electrons, pointing with their north poles to the nucleus and the other 4 electrons with their south poles. For He the two electrons are directed to each other antiparallel. Did you see the correspondence to Paulis exclusion principle?