On tanks, the weight keeps the turret in place, but on ships there are clamps underneath the ring as keepers. On the Iowa class battleships, if the ship were to turn turtle, the guns will remain in place because of these keepers. If in doubt, watch Ryan's videos on Battleship New Jersey. He takes a camera down into these spaces and shows all the components and such. Really interesting videos on Utub.
Not all BS used keepers, Bismark didn't but a lot of American and British ships do. They used them to keep the ring gears and turret motor pinions aligned during heavy weather. On the Iowa class there are 3 large electric motors used to rotate the turret. The guns elevation motors were hydraulic though. There are also locking pins to keep the turrets from rotating on their own in heavy seas, as well as pins on the gun barrels themselves.
I think on the M1A1 Abrams, there are two sets of carrier bearings as the turret is all in one unit, the floor rotates with it. An IED blew this one off.