Battleships can survive close hits by airburst nukes. To defend against this, the opponent must either use massive overkill, or use underwater bursts near their own coasts. Either approach has dreadful economic costs.
War is the art of making the opponent's costs exceed their resources. One way to create costs is to make weapons that are unreasonably durable—the battleship is the extreme end of the spectrum.