I wrote up a fairly lengthy explanation of this question a few months ago. I'll copy it here for you.
The world’s navies stopped using battleships because battleships lost the cost/capability battle when compared to aircraft carriers and heavy cruisers. Everything a battleship can do can be done either more cheaply or more effectively by these other classes of vessels. Essentially by the end of WWII the battleship represented a comparable investment to an aircraft carrier that was less capable of defending itself and less capable of engaging the enemy.
For comparison, consider the US Iowa class, and the US Essex class, the most capable battleship and carrier class of the war respectively. The Iowas cost approximately $100 million dollars apiece in the 1940s. The Essex class, with 90 plane airwing cost approximately $80 million. Add three Fletcher class destroyers as escorts at $6 million apiece to make the costs equal. That’s also about 3000 men for the battleship, and 3600 for the carrier group. Alternately, you could purchase two Baltimore Heavy Cruisers (40 million?) and a Brooklyn class light cruiser (20 million?) and 2800 men. The only estimates I could find quickly for cruiser cost are not very reliable, we’ll settle for saying you could buy 2 heavy cruisers.
A look at the capabilities that $100 million 1942 buys is very poor for the battleship. Offensively the battleship can engage surface ships, aircraft, and shore installations. It’s strike range is variable but tops out around 23 miles. It brings very heavy firepower to bear and is capable of destroying nearly any target. The HMS Hood, IJN Kirishima, and HMS Glorious were all crippled or destroyed by battleship gunfire. Against shore installations they were somewhat less effective. The naval bombardment at Normandy failed to knock out most of the shore defenses and while Iwo Jima and Okinawa were heavily bombarded the ships were unable to destroy many of the underground tunnels. Henderson field was bombarded by Japanese battleships but was only put out of commission for a short time (although many of the planes had to be replaced). Against aircraft battleships were not very effective as offensive weapons. They tended to be targets instead, most battleships lost in WWII were to air attack.
By contrast, the cruisers offer the same bombardment capability as the battleships with somewhat less range. They also used smaller crews and because they cost less could afford to be deployed in multiple positions. They were capable of engaging any size target with some effectiveness. Several American cruisers, the Atlantas, were specialist anti-air fighters and carried large AAA batteries. The cruisers of most other nations also carried large torpedo batteries. This made them deadly against all surface targets. The cruiser forces of the IJN were especially deadly because of their long lance torpedo which had twice the range and firepower of any other torpedo during the war.
Fleet carriers knock both battleships and cruisers out of the race completely when considering offensive capabilities. They have a strike range of several hundred miles, many times that of any other surface ship. They are also capable of engage surface ships, shore installations, aircraft, and submarines effectively. A battleship is wholly incapable of engaging a submarine and must flee from it. They can also fulfill those roles simultaneously because of the large air wing. A US fleet carrier could launch strikes whose targets were “the entire enemy fleet”. Those strikes could also come in from multiple angles dividing the defense of the enemy with torpedo bombers on the deck and dive bombers attacking from above. At the same time the carriers fighters can actively be engaged in destroying the targets own airwing. These same planes can also be used as scouts to find the enemy long before a battleship could ever see one. In terms of destructive capability the bombs and torpedoes of an air wing are the equal of the battleships big guns.
Defensively it might seem that a battleship has an edge. It carries heavy armor and many watertight compartments. This is not a true measure of defense however because a battleship may lose combat capability long before it is actually destroyed. KMS Bismark absorbed hundreds of shell strikes and several torpedoes before finally sinking. He had lost all ability to counter attack long before that however. HMS Prince of Wales and USS North Dakota were both knocked out of battle by single lucky hits. IJN Hiei was so damaged in a night battle by close range gunfire from US cruisers at Guadalcanal that she was easily dispatched by aircraft the next morning. Her hull was proof against the cruiser’s fire but her superstructure took heavy damage (Neptune’s Inferno, Hornfischer). At Pearl Harbor and Taranto few battleships were permanently sunk, but many were forced into repairs lasting over a year, removing them from the war for a time. Additionally the only defense of a battleship from submarine attack was evasive maneuvers. When this didn’t work even a single torpedo strike could remove a battleship from the war for months, this happened to the USS North Carolina at Guadalcanal.
By contrast, a carrier is able to engage all of her attackers. Simultaneously. Attacking aircraft will be met by the fighter wing and attacking submarines can be attacked with torpedo bombers carrying depth charges. All of these threats can also be engaged beyond attack range. This means that a carrier can dispatch many threats before they are even a danger to it. Her scout aircraft also means that the odds of successfully sneak attacking a carrier are much lower. A carrier group has good odds of not sailing into an ambush (although it could happen, HMS Glorious encountered KMS Scharnhost and Gneisenau in a heavy fog near Norway where the Germans sank her). A battleship by contrast must engage all threats at visual range where they are within striking distance of its hull. In our above $100 million example the carrier also has escorts which can aide in her defense. This makes a carrier much harder to destroy than a battleship. Realistically only submarines and other carriers were capable of reliably sinking a carrier. Meanwhile, a carrier could easily dispatch a battleship.
So that is why $100 million was better spent on a carrier. It offered better offense and better defense. It was also capable of much more reliable sinking its rival, costing the enemy their $100 million. One carrier could damage or dispatch a number of battleships. A single battleship could not hope to dispatch several carriers.
They were to expensive, took to long to build and most importantly, to easy to damage. Mines and torpedoes made them to easy to sink or damage in World War One. Aircraft made them even more easy sink or disable in World War II. Battleships look awesome, but by 1942, it became apparent they took to many resources for the benefits they gave to the navies of the world. That is why, in 1942 and 1943 the British, Germans, Americans, Soviets and Japanese all cancelled the Battleships they were building. Two exceptions to this rule were the French battleship Jean Bart, which was seventy percent complete in 1940, when she was moved to Casablanca in 1940. The French navy completed the Jean Bart in 1949. The Royal Navy canceled the battleships Lion and Temarie in 1942, but decided to build HMS Vanguard anyway. That ship was finished in 1946 and used old 15 " guns that were left over from when the small battle cruisers Glorious and Courageous were converted to aircraft carriers in the late 1920s. The Imperial Japanese Navy cancelled the fourth Yamato class battleship and converted the Shinnano, the third Yamato class battleship, into an aircraft carrier. By 1944 it was very apparent that the aircraft carriers had replaced battleships as the most important capital ships.