In fact it is possible for a ship to be top heavy and still not fall over, it takes a certain set of circumstances to tip a ship.
If a ship is vertical, then it can be as top heavy as it likes and stay upright, but the more it is allowed to heel over, the more likely it will turn turtle.
Ships are designed to take a certain amount of heel, the greater allowed heel, then the less top heavy the ship can be made.
There are tilt tests carried out on all ships, where the centre of mass along a line axis donw the ship is compared to the point around which the ship revolves along a line down the ship when heeling.
Usually there is a vertical differance in height between them and the rotation point is higher than the centre of mass.The greater this distance then the more stable the vessel is, but it can change under all sorts of conditions.
Things that would change this are, amounts of fuel, and freshwater on board, cargo loading, and on a warship even the weight of the crew can be significant, since warships are verymuch more heavily manned than cargo vessels.
It is not just the weight itself that is important, its the weight distribution, for example, a trawler may well be very stable in port, or at sea in normal conditions, but when the booms are out, and the superstructure ices up, such as might happen off Greenland, things can become extremely dangerous.
On some ships there is a measuring device, which looks a bit like a manometer, or sometimes its just a moving pointer attatched to stuff and this displays the the stablity of that ship at at any given moment. I don’t know exactly how it works, but it is based upon the way the ship moves about an axis along the length.
All ships are supposed to be inspected for stablilty issues, a ship that has been designed to be stable may unintentionally become unstable through changes in use, where differant equipment is fitted. This happened to Mary Rose, Henry VIII flagship.
She was stable when built, but the addition of extra guns, plus the extra crew complement to man them, and the extra crew that was put on as a boarding party(which was on the main deck at the time - ie relatively high up) and where she turned water flowed into the lower gun ports which were already closer to the water line due to overloading, and over she went, in just a few seconds, taking virtually all her crew with her.