There are many reasons why cats knead. Especially during their kittenhood, kittens use kneading to stimulate their mother's mammary glands to produce more milk, thus helping them obtain more milk.

Kneading may be a way for cats to express pleasure and relaxation. When cats feel comfortable and safe, they may knead to recall happy memories from the past, especially the time spent with their mother.
Kneading helps cats mark their territory, especially cats in heat, as a way to signal to other cats. Cats in heat exhibit kneading behavior when they are eager to mate.