The answer requires a deep dive into the history of domesticating and milking animals as well as the climate of the setting. The mutation that allows for lactose tolerance appears to have occurred independently at least four times in different parts of the world, as recent studies have found variations in the gene. Here’s a very brief outline.
Humans certainly made the connection between animals nursing their young and humans doing so well back into history. Also certainly they understood that animal milk could in emergencies be used to nurse babies and even adults. The problem lay into keeping the milk good in an age before refrigeration. Somewhere along the way, people discovered that fermenting or acidifying milk converted it to longer-lasting forms. Cheese, yogurt, and kefir were some results. Those forms are usually - not always - lower in lactose and/or contain live bacterial cultures that digest lactose.
Like many aspects of western culture, these inventions seemed to have first appeared in the Middle East, with the oldest evidence from around 5000 years ago. The area swarmed with cattle, sheep, and goats, milk was plentiful. Exactly how and when that culture moved into northern Europe has been hotly disputed, but it appears to be highly correlated with the spread of Indo-European languages. As milking cultures moved north it spread into areas with true winters that would preserve milk for longer. (There’s a line between the south where oils are common and the north where butter is common.)
Isobars, like the ones that show temperatures on weather maps, show that Middle Easterners are around 50% lactose tolerant [note: corrected], with the percentage soaring with latitude until it reaches 90% or more in Scandinavia. (All numbers are approximate because no population-wide studies have been done. The early studies were especially bad, with tiny numbers tested using huge lactose loads. I read them all and I’m still appalled.) The assumption is that being able to freely drink milk or eat milk by-products is advantageous so the mutation, which is recessive, nevertheless spread through populations which depended more heavily on milk. Lactose appears to help digest calcium. The colonization of the rest of the world by northern European nations led to widespread LI that disturbs the nice clean lineage.
The difference between the Middle East and East Asia is that east Asians depended more heavily on unmilkable pigs than the milkable meat animals. However, areas which raised large numbers of horses or cattle, like Mongolia and south India, use more milk by-products and so have higher percentages of LI.
Nomadic indigenous peoples are less dependent on herd animals and largely have lower levels of LI. Interesting exceptions are peoples just south of the Sahara, who have so few other provisions and so of necessity independently became milk drinkers.
The reality is that most people, including those like me who are badly affected by large amounts of lactose, can have small amounts of lactose without ever noticing. Even in western cultures many adults stop drinking milk as adults, so the issue seldom arises. Obviously, extremely sensitive people tend to disproportionately see doctors, get tested, and know if they are LI and should avoid milk. As East Asian countries become westernized milk products have been introduced without causing a diarrhea crisis.
tl;dr If your ancestors drank milk you probably can too; if not, probably not.