HMS Venturer (P68)
Many subs sank subs during the WWII.
In fact, subs were among the most effective sub killers in WWII.
But, WWII torpedo technology was relatively primitive - in general they ran at a fixed depth and along a fixed, straight line. Hitting a fully, deeply submerged submarine (one NOT on the surface, or just below it at periscope depth) would be a million in one shot both because of the added third dimension and because technology of the day (sonar) was not accurate enough to get an exact fix on a deeply submerged sub for a torpedo shot.
In both World wars, subs sank each other either when both were on the surface, or when one was at periscope depth and the other on the surface. In other words, subs sank subs the same way they sank surface ships; on the surface. ONE time, a submerged sub sank a submerged sub. A British sub, the Venturer, at periscope depth, sighted and sank a German U-boat (the Type IXD2 U-864), traveling on schnorkel (at periscope depth) off the coast of Bergen (on the way to the Far East). Again, this was not a truly submerged versus submerged attack, as it used standard sub vs ship attack methods (though with a deep depth setting on his torpedoes). (Source: "Hitler's U-boat War" Vol II, Clay Blair, pg 692).
Details: As Venturer continued her patrol of the waters around Fedje, her hydrophone operator noticed a strange sound which they could not identify. The hydrophone operator thought that the noise sounded as though some local fisherman had started up a boat's diesel engine. Launders decided to track the strange noise. Then, due to poor adherence to proper periscope usage protocol on the part of U-864's crew, the officer of the watch on Venturer's periscope noticed another periscope above the surface of the water. Combined with the hydrophone reports of the strange noise, which he determined to be coming from a submerged vessel, Launders surmised that they had found U-864.
Launders tracked U-864 by hydrophone, hoping it would surface and allow a clear shot. But U-864 had detected the presence of an enemy submarine, and remained submerged, starting to zigzag. This made U-864 quite safe according to the assumptions of the time.
Launders continued to track the U-Boat. After several hours it became obvious that she was not going to surface, but he needed to attack it anyway. It was theoretically possible to compute a firing solution in three dimensions, but this had never been attempted in practice because it was assumed that performing the complex calculations would be impossible. Nevertheless, Launders and his crew made the necessary calculations, made assumptions about U-864's defensive maneuvers, and ordered the firing of all torpedoes in the four bow tubes (as a small, fast-attack boat, Venturer was equipped with only four tubes in the bow, none in the stern, and carried a full complement of only eight torpedoes), with a 17.5 second delay between each shot, and at variable depths. U-864 performed a crash dive, straight into the path of the fourth torpedo. U-864 instantaneously imploded with the loss of all hands.
This is a windy way of saying that the sub vs sub battle in U-571, is totally unrealistic. Like the rest of the plot in the movie. (Hey, it's Hollywood. Want to talk about the great realism of 'Mission to Mars?')
This site lists 20/21 U-Boats sunken by allied subs.
Other sources lists up to 25.
At end of WWII the German Type XXI was theoretically able to work up a firing solution by sound without visual help.