Because of Pauli's exclusion principle (
http://en.wikipedia.org/wiki/Pauli_exclusion_principle) no more than one electron with a certain set of qauntum numbers can occupy the same space. For an atom the important quantum numbers are n, l and m and spin.
These quantum numbers can only be integers. below I will denote the restrictions on these quantum numbers that follow from the theory that describes atoms: Quantum mechanics.
n=1,2,3,... determines the energy and size of the atom. It is called the principle quantum number. The higher n the larger the energy of the atom.
l=0,1,2,...n-1 determines the shape of the atom (for n=1 l can only be zero which means the electron has a spherical distribution, a hydrogen atom eg) it is called the angular momentum quanum number
m=-l, -l+1,...,-1,0,1,...l-1, l it is called the magnetic quantum number
Now the lowest energy state in an atom is the one with n=1; from the restrictions given above this means l=m=0. An electron can have two values of spin which is another quantum number. So Pauli's exclusion principle allows two electrons to occupy the region given by n=1. This is called the ground state of an atom.
Now if you want to add another electron you will have to do so at with a different number n. Nature always tries to use as little energy as possible, so the natural next step is n=2. You eneter a new 'shell'. There are few possibilities for the other quantum numbers now. l can be 0 (with m 0) or l can be 1 with m -1, 0 or 1. Each of these possibilities can have two electrons so in the n=2 shell there is room for 8 electrons.
By adding another electron, by Pauli's exclusion principle, you will have to go to yet another higher value of n. This will higher the energy appreciable. So from 7 to 8 electrons in the valence shell costs less energy than adding another electron for which you have to go to a higher number of n.
You can picture this by realising n also alters the expectation value of the distance to the nucleus of a shell. For small n the electrons are close to the nucleus (and thus have a small energy, as they are tightly bound to the nucleus!). For larger n the expectation value of the distance to the nucleus will increase and thus the electrons with this large n will be only loosely bound (also because some of the inner electrons are shielding the nucleus charge).
So you see, it is not only 8 electrons in a valence shell that nature likes. But the numbers 2,8, 20 etc . These are called magic numbers.