Kittens knead the nipples of their mother while they’re nursing. One of the most common reasons for your cat to adopt this behavior later on in her life is if she was separated from her mother too early.
Wild cats used to knead and pat down the foliage to make the ground softer for sleeping or giving birth. So, your cat might instinctively be doing what her ancestors did when it was time to sleep.
Cats can feel quite vulnerable when going to sleep, so, they might use kneading and biting to create a sense of safety that their mothers were responsible for.