I can’t find any references, but I’d heard in the past that it’s the opposite with us – that the curl in our fingers that we see when we lay our hand palm up disappears only when dead because only then do nerve impulses stop affecting them..
In birds, it actually requires a muscular contraction to release their grip on a perch. The fact that their grip locks down physiologically/anatomically allows them to perch securely while asleep (or dead).
The classic positioning of dinosaur fossils with the neck flexion forcing the head above and behind the body (opisthotonic posture) is from “perimortem muscle spasms resulting from various afflictions of the central nervous system”. Source
My first response to your question was to guess that fluid loss (dehydration) causes the joints to tighten and the legs to curl, but that doesn’t explain why it happens almost immediately. Perhaps “curled” is the default, “at rest” position and it takes muscular control to straighten them?
Oh, hey, look at this!!
“There is no more hydraulic pressure to extend the legs and the flexor muscles revert back to their original length with no resistance, thus the legs curl in.”
(I LOVE the internet!)