Ships have heavy keels in the lower part of the boat to keep them from capsizing. On the other hand fish have the keel on the top of their bodies. If the paired fins stop functioning to keep the fish balanced then the fish turns over because the heaviest parts tend to sink. This is why fish turn upside down when they die.
Although not all fish that hang upside down are dead, they can start swimming upside down if they have a swim-bladder disorder/disease. This happens when the swim-bladder, the gas-filled organ that controls the fish’s buoyancy by deflating/inflating, is no longer able to control itself. This can cause the fish to stay at the bottom of the tank, float hopelessly at the top, bob around head first at the bottom or swim on its side or swim upside. Not too dissimilar to a diver with bad buoyancy and mal-arranged weights.