A completely filled outer electron shell is stable because it can not gain any more electrons, it is full. Being completely full it has no desire to lose electrons thereby losing its stable structure.
Neon for example has 10 electrons. Its is
The
Oxygen starts with an electron configuration of
This is two electrons short of the stable structure of Neon. By gaining two electrons Oxygen can achieve this stable structure so
Sodium starts with an electron configuration of
This is one more electron than the stable structure of Neon. By losing one electron Sodium can achieve Neon stable structure so
Elements electron configurations are all about achieving stability.
The most stable electron configurations are those of the noble gases.