It may have a real function in other situations (milk production) but I believe the proximal cause for her nightly kneading is simply how good it feels which puts her straight to sleep afterwards. I expect it releases a lot of oxytocin/opoid type neurotransmitters. It makes me feel a little.... used. Not to mention the pain!