The ability to digest milk late in life is due to a mutation in the LCT gene, which codes for lactase. To understand why only 20% of people have this mutation, we first need to look at how mutations spread in the population.
Gene mutations are random. Some of them are useful to man, according to the conditions in which he lives, some are neutral, and others are harmful.
If a mutation is very harmful to health and life, it does not spread, because its carriers do not have the opportunity to live long. If, however, the mutation does not have such a strong effect, it can still spread through the population thanks to chance.
In the long run, the factor of randomness can help a mutation to spread, for example if in a war mostly people who carry the mutation survive by chance. This is called "neutral selection".
But along with randomness, the principles of selection are at work.
"Positive selection" - If a mutation improves a person's ability to survive, people with that mutation gain some kind of advantage in life - more access to resources, better appearance, or something else that allows them to reproduce more successfully. Over time, the mutation spreads.
"Negative selection", also known as purifying selection, occurs when a mutation is harmful, reducing the fitness of an organism. Negative selection works to remove these harmful mutations from the population.