I was thinking about epigenetic factors, which lead to silencing of the respective genes (i.e. lack of lactose in your diet somehow leads to the DNA methylation which silences the genes encoding lactase).The ability to digest lactose depends on the secretion of lactase in the small intestines which is something virtually all mammals including humans do as infants. But in most mammals and humans, other regulatory genes turn-off lactase expression in early childhood. In the absence of lactase, gut bacteria do digest the lactose but the byproduct is a lot of gas and a surge in bacterial populations which causes discomfort and other symptoms when lactose-intolerant people eat foods with that sugar.
In the past 10,000 years, some human populations that switched from hunter-gatherer lifestyles to pastoral ones have evolved a genetic variant in which lactase continues to be secreted into adulthood. The percentage of the population that can handle lactose varies widely (being high in northern Europe, Tuareg, Ukrainians, Mongolians, etc. and being low in most Africans, most MiddleEasterners, almost all Asians, Indians, and Native Americans).
The genetic variant responsible for the lactase persistence is believed to be a relatively young mutation rather than an atavism, but they keep changing their mind about everything...