Sounds like he might have had what is called "Red Leg", which is a bacterial infection, probably from the Aeromonas bacterium (and this is often from water quality problems). Unfortunately, once they start to flip over on their backs like that, the end is near.

Swim free now little guy!

Barb