Kneading is a way for cats to show affection to their owners. When a cat kneads on you, they are essentially saying "I love you and trust you."
Cats have scent glands in their paws, so kneading is a way for them to mark their territory. This is especially common in male cats.
Kneading can also be a way for cats to soothe themselves. It is a repetitive behavior that can be calming and relaxing for them.
Kneading is an instinctual behavior that kittens learn from their mothers. Kittens knead on their mothers to stimulate milk production.
Kneading can also be a way for cats to get some exercise. Stretching their paws and claws helps to keep them strong and healthy.
Sometimes, cats knead simply because they are playful. They may knead on a toy or your lap as a way to initiate play.