Well, there used to be another writeup here, but I guess it left, leaving me all alone. Bummer. Enjoy my meager contribution.
Bugs move their legs by increasing and decreasing the pressure of their internal liquids. When bugs die, the pressure decreases, and the legs curl up. Bugs are top heavy, so they flip over.
Biology solves mysteries.