I've read that it can be a reflex, such as for cats: When pinned by a larger creature they lash out with rapid kicking/scratching motions, attempting to get at the stomach or vunerable areas of a larger animal.
Since its a reflex that they don't directly control they attack the offending leg, pinning it down and biting it. Its an uncrontrollable motion just like a human who can tickle their own foot compared to someone who can't or who just isn't ticklish.