To me, they look a bit like submarines. The proportions seem so off and because the monitors look so heavy, it seems like they should just sink below the surface anytime water washes onto the top.
Let me break down your question a bit.
First, Monitor as a ship classification can actually mean several different types of design. This is the USS Monitor. This is the HMS Erebus, which is also a monitor. As a classification, monitor means a shallow draft coastal warship mounting several very heavy guns in a turret (sometimes more than one turret). Other than riverine combat they are usually used for harbor defense.
I imagine you are interested in the Monitors built for the American Civil War. The simple answer to how did they stay afloat is that they were buoyant enough to do so. Buoyant objects displace a greater weight of water due to their volume than their mass. This allows the water to support them. If you look at the first image I linked above you will see that the USS Monitor has a broad, shallow hull. This means that she is very much like a raft (earning her the sobriquet “a cheese box on a raft”) and has a large surface volume for her mass. This allows the ship to float. You are not alone in your doubts though, many at the time thought she would sink at launching as well and the Monitor’s designer John Ericsson stood on her deck as she was launched as a show of confidence in his design. If you look again at the picture you can see that the hull is subdivided into a broad upper section and a narrow lower section. Only the turret and the upper section were armored which reduced the amount of buoyancy needed by lowering weight.
All of this gave the USS Monitor a freeboard (height above water) of around 18 inches if memory serves. This was plenty for shallow rivers and bays where most Civil War Monitors operated. Unless they took on water the ships floated just fine. However, the low freeboard did make them vulnerable to being swamped. If even small waves washed over the deck water could come in the vents or around the turret ring. To prevent this from happening while the USS Monitor was being towed to Norfolk, and later Charleston, she was fitted with a temporary smoke stack. That’s why she looks so different in this well known woodcut of the sinking. Those smoke stacks would have been removed or shortened before battle.
The second weak point was the turret ring which supported the weight of the turret. To prevent water from leaking in at this point Ericsson built the Monitor with an enormous brass ring for the turret to sit on. The weight of the turret pressing down on the ring was supposed to give a waterproof seal. We don’t know how well this design would have worked because the then commander of the Monitor John P. Bankhead, didn’t trust it. Instead he had the turret jacked up and the space between the turret and the ring packed with oakum. Oakum is a traditional type of caulking made from rope. When the Monitor was caught in a heavy storm off Cape Hatteras the oakum caulking failed and the ship began to take on water. The crew was unable to save the ship and she sank off the North Carolina coast.
You can read more about the Monitor in Monitor by James Tertius deKay.