This is not stretching paws. What the question is referring to is cats extending their toes and then contracting them when you pet them. It does look as if they are stretching or exercising their toes but they are not.
Cats normally enjoy being the recipient of human petting. They relate to the person doing it as their mother. This prompts them to knead their mother’s nipple. As there is no nipple the kneading will be against the surface on which the cat is resting. This can a person’s lap or on the bed as two obvious examples. The softer the surface the more likely it is that they’ll knead it as it replicates their mother’s breast.
Feline kneading is an automatic and instinctive response to many kinds of human interaction, not only petting. For instance if you talk to your cat nicely and he is near you he may knead once in slow motion. It often goes with the slow blink which is also a sign of contentment.
The purpose of kneading is to express the flow of milk. It is not to stretch the paw. It should never be stopped even if the claws are digging into your flesh as it would confuse your cat. This is an emotionally warm moment. To suddenly do the opposite is unwise and it does not foster a close relationship. Trimming claws is the way to prevent it hurting.
FYI – when a newborn kitten suckles at their mother’s nipple they have selected and they reuse their favourite nipple and always return to it. The same applies to the other kittens of the litter. The mother may purr and the kittens purr in response while drinking and kneading!
P.S. Cats stretch their backs when using a scratching post to slough off the top layer of keratin of their foreclaws. When cats do this they are (1) depositing scent from their paw pads onto the scratching post and (2) ‘sharpening’ their claws as mentioned and (3) stretching their back and body in general.