It is due, first due to the degeneracy of the energy shell (i.e. how many energy states that have that shell's energy) and also due to the pauli exclusion principle.
First, the higher energy shells have bigger degeneracies. In simple terms, there are more orbitals in the n=2 shell than there are in the n=1 energy shell. Thus, they can hold more electrons. Each orbital can hold a maximum of two electrons with opposite spin due to the Pauli principle. So the end result is:
n=1 Shell: 1 orbital = 2 electrons
n=2 Shell: 4 orbitals= 8 electrons
n=3 Shell: 9 orbitals= 18 electrons
The number of orbitals is determined by the number of possible angular momentum states for the electrons in the atom, which is predicted by the Schrödinger Equation. So, while your pattern may seem nicer or more aesthetic, it is not what the Schrödinger Equation predicts, so it does not make more sense mathematically in the end.