Why do cats make biscuits on your bed? To use cuteness as a way to trick you into trusting them is a perfectly reasonable answer. But that's not the scientific reason. In fact, there may be several. "Some of these are just theories because we don't know," says Kansas State University veterinarian Susan Nelson. "Cats don't get the funding for studies like dogs do."
From Scientific American:
Kneading begins in kittens as an instinctual behavior that is associated with feeding—it's not something cats ever have to learn, says Leticia Fanucchi, an animal behavior scientist at Oklahoma State University. "The way the behavior starts is: they knead the mother's mammary glands to actually suck the milk," she says. The kitten's kneading, she adds, stimulates milk flow and may also release oxytocin, a social bonding hormone, in the mother[…]
"It's possible that some of these juvenile behaviors we see that used to be directed at the mother are now directed at the owner," says Kristyn Vitale, a certified applied animal behaviorist at Unity Environmental University. "Cats will knead on preferred people in the house or their favorite person, so kneading can also be that affiliative, social behavior that can help build a bond."[…]
The behavior also has physical consequences. Fanucchi says that kneading stretches a cat's muscles and activates scent glands in its paws, which can be a friendly way for the animal to stake its claim on a favorite human or sleeping spot. Things can get a little messy, too. "Some of these cats start drooling as well when they knead—those are the really happy guys," Nelson says.