Kittens' kneading behavior can be traced back to their kittenhood. When kittens snuggle in their mother's arms to nurse, they suckle vigorously while kneading their mother's belly with their two little paws, which helps to produce more milk.
In mammals, milk production generally requires glandular stimulation to trigger the release of oxytocin, leading to milk production. Milkmaids on farms are well aware of how to maximize milk production in cows, employing various methods to stimulate their mammary glands. It's rumored that farms now breed cows that produce milk without artificial stimulation, saving considerable labor. However, cats still require glandular stimulation to produce milk, so the kneading behavior of kittens is a survival instinct. To get more milk, kittens constantly stimulate their mother's mammary glands with their paws. 
As kittens grow up, they no longer need to nurse, but they feel warm and safe when snuggled up to their owners. Memories of their kittenhood resurface, and they begin to knead contentedly on their owners. However, if owners don't trim their kittens' nails regularly, this process could potentially injure them.
Kneading behavior isn't a conditioned reflex; cats don't unconsciously knead their owners. This process requires the cat to recall its kittenhood, making it a genuine behavioral response. Kneading only occurs when a cat deeply trusts its owner and sees them as its mother. It's also the most sophisticated way a cat says "I love you."