A battleship as built can be seen as the sum of the answers to a whole series of questions, ranging from the highest levels of national strategy down to the most mundane issues of how best to operate a large and complex pile of machinery. A full and comprehensive analysis of all of these questions and their answers for even a single ship would require a whole book (actually several bookcases in danger of structural collapse), but I'll attempt a high-level overview here.
The first major question that shapes a ship is "What do we want our fleet to do?" The answer is informed by the strategic situation and the resources available, because there's never enough money as we'd like. We've previously looked at the basics of naval strategy, and the broad choices available to a navy. But how do battleships fit into this framework?
Battleships were essentially symbolic of sea control from the 1860s up until about 1940, when the torch was passed to the aircraft carrier. Control of the sea involves being prepared for the worst possible fight the enemy can throw at you, while sea denial forces can afford to pick their battles, striking where the enemy is weak and circumstances favor them. This isn't to say that sea control forces can never refuse to fight when the odds are too badly against them, but avoiding a fight surrenders a portion of that control. Avoid too many, and you're no longer master of the seas. While there were weapons in the late 1800s that could defeat a battleship some of the time and under certain circumstances, it took until the 1950s to reach the point that the heavy guns of the battleship were no longer an important part of a balanced fleet. The fleet aspect is very important. While I focus most on the battleships, they did not work alone, and their supporting ships dealt with many of the supposedly lethal threats. Nor were battleship tactics static. As new weapons made previous options too dangerous, navies invented new ones.
The first weapon that was supposed to doom the battleship was the torpedo. Before its invention in 1868, the only weapon that could defeat a ship was a big gun, which required a big ship to carry it.1 Torpedo boats were small and cheap, and each could, in theory, sink a battleship. This was the position of the French Jeune Ecole, who claimed that the traditional close blockade was now impossible. The development of the destroyer reduced the torpedo threat to a manageable level, and the close blockade was replaced by the distant blockade. The distant blockade, such as the British blockades of Germany during the World Wars, was usually enforced by light units, but they had to be covered by a battle fleet to prevent heavier enemy units from snapping them up.
In the runup to WWI, the submarine had taken the place of the torpedo boat as the potential battleship killer. Even such luminaries as Jackie Fisher believed that the submarine would make it impossible for the battleship to operate in the North Sea. What actually happened was that the slow speed and limited vision of the submarine made it mostly ineffective against warships with appropriate screens.
After the war, air power advocates such as Billy Mitchell claimed that aircraft would sink any ship which approached the coast. At the time, aircraft simply were not up to matching this boast, and without better sensors than the Mk I eyeball, even detecting ships at sea was a serious problem. During WWII, the carrier replaced the battleship as the main instrument of sea control, but even so, this represented a defeat for the sea denial advocates. Battleships gave valuable service screening the carriers from both air and surface threats. Even as late as the early 50s, aircraft carriers remained vulnerable to surface attack at night or in bad weather,2 and it was only the lack of foreign battleships that allowed the sea control powers, Britain and the United States, to place their ships in reserve. Nuclear missiles3 and improved aircraft finally rendered them obsolete except for bombardment work.
After figuring out that battleships were a good choice for their strategy, powers had to figure out how many to buy. The British, whose goal was control of the seas surrounding Europe,4 adopted a two-power standard, declaring in 1889 that they would build a fleet equal to the fleets of the next two strongest powers combined. This persisted until Germany began the dreadnought race, when it became 160% of the next-largest fleet. The US first attempted to build a fleet capable of keeping likely threats (in practice, Germany) from being able to establish a base in the New World, and later a fleet capable of overmatching the Japanese and equal to that of Britain.5
I should emphasize that while some countries bought battleships based on a sound strategic rationale, a lot of them didn't. Ships were bought because they would add to national prestige, or because the Navy was trying to gain political power. But regardless of the reasons for the purchase of battleships, the problem then passed into the hands of the naval architects who had to design the ships.
1 Strictly speaking, ramming was sometimes proposed as dooming the large, gun-armed ship even earlier, but I'm going to stick to weapons that actually worked. ⇑
3 Most SAMs have some anti-ship capability, and their secondary anti-ship/bombardment role was an important consideration in US nuclear-tipped SAMs. ⇑
4 This translated into control of the global seas thanks to naval geography, at least until the early 20th century. ⇑
5 At least in theory. In practice, the main limit on the USN battle fleet throughout much of the era was Congress, who was often suspicious of the rationale for naval power. ⇑