Opiates are present in the breastmilk of all mammals. These opiates calm the baby who quickly learns that Mum is the source of an addictive, soothing, pain-releiving form of nourishment. This strengthens the mother-child bond and encourages continued feeding, which ensures the baby gets all the nutrients they need to survive and grow.
A protein in milk called casein breaks apart during digestion to release a swag of opiates called casomorphins, one of which has about 1/10th the pain-killing potency of morphine. The casein in cow’s breast milk is much more concentrated than the casein in human breast milk, and cheese is a highly concentrated source. Casein fragments that pass into the human bloodstream from dairy products reach their pain-releiving, drug-like peak about 40 minutes after being consumed. Cheese also contains an amphetamine-like chemical called PEA (phenylethylamine).
The mother’s milk of all mammals is species specific: designed specifically for the baby of that species (rather than some other species). When a human breastfeeding mother drinks cow’s breast milk, some of the cow mother’s caseins pass through the human mother’s digestive system into her bloodstream and then into her own breast milk, in amounts large enough to irritate the baby’s stomach, causing colic.
Like heroin or codeine, casomorphins have an antidiarrheal effect because they slow bowel movements, which might be why cheese is constipating for so many people. With lactose (the sugar in milk) being difficult to digest and often resulting in diarrhoea, you would hope the two might cancel each other out, but the effect can be more erratic, unfortunately! A little irritable-bowelish: runny one minute, blocked up the next, with all sorts of bloating and smelly wind to cap it all off.
Reference: “Breaking the Food Seducation: The hidden reasons behind food cravings- and 7 steps to end them naturally” by Neal Bernard MD