I heard something different from what /u/Peachadee answered. I heard that cockroaches, like many insects, move their legs through hydraulic (pressure-driven) action. By default, their legs are fully contracted and curled up under them, and they have to intentionally relax them to move around. When they die, their legs contract, which often flips them over onto their back.
Latest Answers