Why do not metals gain electrons and non-metals donate electrons?
First, it is a high-school rubbish that was kept only because of lack of desire to revise basic courses.

Can metal gain electrons? Certainly, YES. Sodium has several compounds with negative oxidation state, many transition metals have extensive chemistry where the metal is in formal negative oxidation state and so forth.

Can nonmetal lose electron? Certainly, as in nonmetal-nonmetal compounds it is unavoidable.

So, what is it really about? What is the difference between metals and non-metals?

Before we continue, we have to revisit definition of what metal is. 

Metallic solid (sometimes shorthanded as metal) is a solid with metallic conductivity. It arises from having continuous half-filled orbitals allowing electrons to move freely. Metallic solid perfectly can be a compound (say, $\ce{Ag2F}$). Furthermore, many non-metals under heavy pressure undergo transition into metallic phase.

However, when we are talking from chemical PoV, metal is an element. But what kind of element? The problem is, that the definition of metal in chemistry has a history, and the term was introduced long before many of metals known today were discovered. As such, only common metals were considered and no exotic compounds was known, and certainly before extremely high pressures became available.

Consequently, a metal was characterized by its ability to lose electron (but many elements are capable of doing so) and having metallic conductivity when in form of simple compound. The border cases were either discarded or counted as 'metalloids' - a special kind of non-metal. 

For example, tin has metallic and non-metallic allotropes at ambient pressure. Oups, is it a metal or non-metal ? Well, legally it is considered as a metal. However, antimony, with pretty much the same case, is typically considered as metalloid. 

There is however a strict difference between tin and antimony in than tin is capable of forming normal salts and having a basic oxide, while antimony has only slightly acidic oxides. The reason for discrimination DOES exist. On the other hand, some heavy transition metals, such as rhenium and tungsten do not have true basic oxides.

So, it would be best to define metals by enumerating them. It is, however, easier to enumerate non-metals: commonly recognized non-metals are boron, silicon, arsenic, tellurium, iodine, everything to right and up of that elements and hydrogen. Optionally, germanium and antimony may be included. (Polonium, astatine and some others are questionable cases, since their chemistry is virtually unexplored thanks to their high radioactivity. But for that reason they can be safely ignored)

Said elements have some things in common: they have relatively high electronegativity, form covalently bound or molecular solids, form acidic oxides (if form at all) and do not form simple cations stable in water. All this comes from them having relatively high number of electrons in valence shell and tight binding of said electrons. 

By no mean you should assume that sodium, for example, is eager to lose an electron. Nope, this process results in energy consumption. Only subsequent stabilization of by electron affinity of its partners and ionic packing results in net energy gain. On the other hand, addition of electron to an atom often results in slight energy release.

TL; DR. Non-metals typically has compact electron shells tightly tied to their nucleus and as such are uneager to loose them.