The equivalent of self-descructing a spaceship is scuttling a (sea)ship. All Real navies do have that. In fact, all ships can be scuttled.
All ships have a feature called a sea chest, which is a recess in the hull from which water can be drawn for e.g., ballasting and fire-fighting. Water is pumped into the interior of the ship for whatever purposes through pipes, which are, as I recall, typically somewhere in the region of 15-30cm in diameter. To allow these pumps and pipes to be replaced when necessary, there is a valve at the start of the pipe: you close the valve, replace the pipe, then open the valve again. To scuttle the ship, you close the valve, remove the pipe and open the valve: you now have a fairly large diameter connection between the sea and the interior of the ship, and seawater gushes in at a rate of up to tons per second. Ships are sometimes lost because repairs to the sea chest inlet pipes go wrong (e.g., Sea Breeze off south-west England in March 2014.
Perhaps a closer analogy would be aircraft. Some military aircraft, such as the Lockheed U-2 do have a self-destruct mechanism which destroys parts of the plane with explosives to avoid them falling into enemy hands. Likewise, the when a U.S. EP-3 aircraft collided with a Chinese fighter plane sustaining damage that forced it to land, the plane's crew destroyed much of the equipment on board (by pouring coffee into the electronics!) and dumped more into the sea. That probably didn't involve explosives but the crew of the downed helicopter in the Osama Bin Laden raid did use explosives to destroy sensitive parts of that craft after it crash-landed.