Submarines were good for stealth and surprise, but not stand up fights. They were most effective against merchant ships without guns.
Compared to warships, they had less guns and armor and speed. In a straight up fight, the submarine’s best option was to submerge and hide. Submarines might aspire to sinking an aircraft carrier with a torpedo, but in reality there would be so many destroyers and cruisers escorting the carrier that they wouldn’t be able to get close without being spotted.