...but if the Strait is guarded such that they can't get them without braving an enfilading strafe of torpedoes, then it wouldn't do much good even if they knew where they are.
From this comment by the OP, and others like it, it seems they don't appreciate the tactical limitations and vulnerabilities of a WWII submarine. I'll address that. While WWII submarines can be devastating to unescorted (or, earlier in the war, even escorted) merchant ships, they are extremely vulnerable to even small warships.
First thing to realize is WWII submarines aren't really submarines like modern submarines are. They are first and foremost surface ships. They spend most of their time on the surface where they can see (relying on lookouts with binoculars), move quickly, and use relatively cheap and plentiful deck gun ammunition to sink vulnerable merchant ships. It wasn't until the revolutionary Type XXI, completed at the war's very end, that the submarine would be able to spend the majority of its time under water.
Underwater a WWII submarine is very slow, has very limited battery power (a few hours at any kind of speed), limited breathing time, and must fire relatively short ranged (1000-5000 meters effective range), slow (20-40 knots), unguided, expensive torpedoes which are in limited supply and slow to reload. A Type VII submarine had only 14 torpedoes and just 6 tubes (4 bow, 2 stern). Once they were fired it could take an hour to reload. Hitting a slow, unaware, leisurely zig-zagging merchant ship was tricky enough and it usually took all 4 bow torpedoes to guarantee a hit. Hitting a fast, wildly maneuvering warship aware of your presence is almost impossible.
A German Type VII submarine, their most plentiful, could do 18 knots on the surface, but just 8 underwater. Surfaced, they had a range of 8500 miles, underwater just 80 miles... at a leisurely 4 knots. While submerged a target had to almost run them over to allow a torpedo attack, they could not chase them down.
While they carried an 88mm deck gun with 220 rounds of ammunition, this is a peashooter compared to what even the smallest destroyer carries. With a single gun, an unstable platform from which to shoot it (ie. the submarine rolls a lot), inferior range-finding gear, slow speed, and no armor... to be caught on the surface by even a well-armed merchantman was suicide. This was exploited by Q-Ships, armed merchantmen made to look like juicy deck gun targets.
If they stay deep they're safer, but also blind relying only on hydrophones (underwater microphones) to detect ships. If they want to use their periscope they must come up to periscope depth, shallow enough so their periscope can reach the surface. It's a tricky process to hold a WWII submarine at periscope depth. Come up a few feet and your scope is sticking up high out of the water and easy to be spotted. Come down a few feet and you can't see anything. The view isn't very good, being at the surface of the ocean and through a series of lenses.
Which brings us to the most underappreciated part of anti-submarine warfare (ASW): airplanes. We like to think of objects underwater as being effectively invisible, but from a high vantage point, like an airplane, a 200 foot long submarine can be seen quite easily at periscope depth. If an airplane spots a submarine on the surface it can be attacked with guns and bombs. At periscope depth it can be depth charged. To avoid attack, the submarine must dive deep to get away. Even if the airplane doesn't get the submarine, the submarine is now slow, blind, and losing battery power. With it's long loiter time, an ASW aircraft could hold a submarine down until a warship arrives to hunt it down with sonar.
With all that in mind, what happens when the German navy attempts to blockade the Strait of Gibraltar with submarines augmented with e-boats, destroyers and other light surface ships. To give it the best chance of succeeding, let's set it in the late summer of 1940 at the height of the Battle of Britain. The RAF is overstretched, the US hasn't entered the war, and ASW aircraft don't have radar capable of detecting submarine periscopes.
The German navy at this point is in bad shape. Never anything like a match for the Royal Navy, the war had started a few years too soon and naval production schedules were thrown into chaos. They had just taken a mauling in the otherwise wildly successful invasion of Norway losing many small ships.
At this point Germany only had 9 destroyers. They started the war with only 21, had since lost 12, and had only since commissioned one. They wouldn't last long with the major Royal Navy base of Gibraltar right there. It's unlikely Germany would risk its remaining overworked 9 destroyers on such a risky mission as blockading the Strait.
The Germans had E-boats, small, fast, expendable torpedo boats, and in some quantity. And, like a submarine, they were also extremely vulnerable to any real warship. Their short range precludes them from being used in this operation. Spain is staunchly neutral, and the south of France and Morocco are Vichy French territory who can still deny the Germans from using their ports.
While smaller ships have a hope of dodging the Royal Navy, larger surface vessels would be target practice. No German capital ship would risk staying in one area long enough for the RN to find them.
So no support from the German surface navy.
What about submarines? At this point in the war, the Germans had only commissioned 25 Type VII submarines of which only 13 remained. Their larger, ocean-going Type IX was too precious to be used in such an operation. At this point they had commissioned 11 but only 4 were left. It wasn't until 1941 that production would ramp up into the hundreds we think about when we think about the U-Boat war, but by then they were losing their technological edge.
This pitifully small number of capable submarines meant not only would the blockade be difficult to maintain, but submarines would have to be taken from the then very successful Battle of the Atlantic probably never to return.
Already, even in the summer of 1940, U-Boats were taking very heavy loses. And this was while mostly avoiding the Royal Navy. You're proposing they take them head on. Let's see what happens.
A submarine operating in the Strait of Gibraltar has all sorts of problems. It's a death trap. A submarine's single advantage and defense is stealth. This can be in not being detectable, but it's also not knowing where it's going to show up next. The enemy has to spread their ASW resources very thin looking for you. If German submarines try to blockade the Strait you know where you look and can concentrate your search in a small and restricted area. Only about 10 miles separates Africa from Europe. If detected there's nowhere to go. Being right next to a heavily fortified and extremely valuable British naval base means retaliation will be immediate and heavy.
A submarine that doesn't want to be detected in the Strait has a fighting chance... if they're moving into the Mediterranean west to east with the currents. The mixing salinity between the Atlantic and Mediterranean made underwater detection difficult, and the currents could be used to transit the Strait silently. It was still a very, very dangerous transit. Out of 62 U-Boats which made the trip from the Atlantic to the Mediterranean, 9 were sunk and 10 turned back. None returned.
But our submarines are on the attack, and a submarine running deep cannot see or attack. Our submarines have to spend their nights on the surface charging batteries and hunting, and their days either submerged avoiding aircraft and saving battery power, or hunting at periscope depth, but also vulnerable to ASW aircraft. Stuck in a narrow box of ocean, they're easy pickings for ASW aircraft and ships who can patrol over the area again and again and again until they've hunted them all down.
In addition to ASW hunters, any merchant ships transiting the Strait can be formed into convoys and protected by heavy ASW escort. Since the submarines are bunched up in the Strait, the same ASW fleet can protect all convoys moving through the gap. Submarines would not be allowed unescorted targets.
Attacking an escorted convoy would be suicide. Even with surprise, even with a wolf pack, avenging ASW aircraft and ships are never far away at Gibraltar. Every attack would pinpoint the submarines' position, and at 8 knots submerged they can't get far before an ASW vessel or aircraft shows up to search.
As for larger Royal Navy ships which might be worth the risk, they will either avoid the Strait until it is cleared, or be heavily escorted and moving at high speed. Capital ships have little place in an ASW fight except to be targets.
To sum up why they didn't try this...
- Submarines are extremely vulnerable to even the smallest warship.
- Submarines have to be surfaced most of the time.
- Submarines must be surfaced or near the surface to attack, vulnerable to ASW aircraft.
- The Germans would only be able to muster a dozen submarines.
- No support from the surface navy.
- ASW search would be relatively easy in the restricted area.
- Convoys could be heavily protected in the restricted area.
- ASW ships and aircraft were close by at Gibraltar.
- The British would react very violently.
An attempt by the Germans to blockade the Strait would be a dream come true for the British. It would draw the entire German submarine fleet away from their very hard pressed Atlantic merchant convoys, and into a fixed area where they can be hunted and destroyed by a relatively small number of cheap, short-ranged ASW warships and aircraft.
For an appreciation of the troubles of a WWII submarine, I recommend the famous fictional but quite accurate German submarine movie Das Boot. They even have to transit the Strait.
I would also highly recommend the historical book One Of Our Submarines, the account of British WWII submarine captain Edward Young. This is an accurate, detailed, and very well written biographical account of submarine life and tactics. He also has to deal with straits, and without the luxury of deep water.
Avoid the dreadful and wildly inaccurate movie U-571.