The answer may have more to do with the attack capabilities of submarines, but what prevented submarines from targeting warships as opposed to shipping convoys? Was anti-submarine weaponry so effective on armed warships to prevent this? Surface ships seem to a layman very vulnerable to this sort of attack.
You are correct that they were not ideally suited for this role. The U-boat was exclusively an ambush predator. Its main advantage, stealth, stemmed from its ability to travel underwater plus its small size and low silhouette on the surface (U-boats prior to 1943 usually attacked while surfaced.)
Stealth was essentially the U-boat’s only advantage, however. On the surface, it was slower than almost any Allied warship and its limited topside armament could hardly be used when the crew was at battle stations. Underwater, it was much slower than its opponents, only able to travel at a brisk walking pace. A U-boat was also completely blind when submerged deeper than periscope depth, and even using the periscope required traveling at low speed while dangerously close to the surface. Launching torpedoes accurately was very difficult when under attack too, which required being on or near the surface anyway. U-boats also had no armor to speak of. Thus the U-boat’s enemies held essentially every advantage…and that’s not even mentioning Allied sonar, radar, and radio direction-finding technologies.
U-boats in both wars did sink quite a few Allied warships, but this was a risky gambit. If a torpedo attack failed due to missing its target or malfunctioning, the enemy ship might then be alerted to the U-boat’s presence. If there were multiple warships present, then even a successful strike would provoke a furious hunt for the U-boat. In these situations, the U-boat has lost its only advantage (stealth) and now must either hide on the bottom or escape while blind at walking pace.
Both World Wars have been referred to as “total war,” meaning a clash of the entire strength of combatant nations. Total war entails not just defeating enemy forces on the battlefield but on defeating his country overall ability to wage war. Fighting on the battlefield requires equipping and sustaining forces, manufacturing, feeding raw materials into industrial processes, transporting war materiel and personnel, and other activities.
Germany in both wars recognized that Britain, as an island nation, was heavily reliant on commercial shipping to bring in the raw materials, finished equipment, and foreign troops it needed. Germany lacked a surface fleet capable of challenging the Royal Navy, so the U-boats (which were more cost effective than surface ships anyway) were used to sever the sea lanes keeping Britain in the war. This is why the U-boats primarily targeted freighters and tankers. A nation cannot effectively fight if an enemy strangles his access to food, fuel, and other key resources.
The US used a similar strategy against Japan in WW2. American leaders recognized that Japan- an island nation with few natural resources- was dependent on food and raw materials brought in by sea. The US Navy’s submarines waged the same war that Germany’s U-boats did, albeit far more effectively. By war’s end, roughly 80% of the Japanese merchant fleet had been sunk and Japan was effectively cut off from their empire. German U-boat admiral Karl Dönitz was ultimately not convicted at Nuremberg of waging unrestricted submarine warfare because Admiral Halsey testified in his defense, basically staying “we did the exact same thing against Japan.”
I am in the process of publishing a non-fiction book about the U-boat offensive against the US East Coast in WW2 if you have any other U-boat related questions.