Longer answer: A cheap commercial sonar isn’t going to find a submarine, even if you know where you’re looking. Submarines are incredible stealthy, and the ocean greatly effects sonar effectiveness, especially from the surface. Due to how it works, surface sonar is nearly useless when trying to locate a submarine.
A popular joke was for us to surface right in the middle of a fleet during war games, or sneak up behind them and take pictures of people smoking and send them to the surface ship’s captain just to mess with them.
With things like towed sonar arrays, and sonar bouys, the playing field can be evened out a bit, but in all the war games I was in, the surface guys could not find us even we told them exactly where we were.
Now imagine that, with an inexperienced submarine crew doing testing, and a surface ship practically incapable of keeping track of us…
“CON, ESM, EMERGENCY DEEP! Hold high signal strength contact bearing 087!”
(From exDM69's comment, I'll figure that the active sonar's power needs to be dialed way down. The theory that a sub's fancy listening gear could get a good fix on a sonar signal that's too weak to give a usable reflection seems hand-wave plausible to a landlubber.)
Detecting sonar doesn’t.
No hand waving needed.
When transiting places like that, there is either an escort, or the sub is surfaced, or the sub moves reaaally carefully. All depends on the mission.
Check out the book “Blind Man’s Bluff” for more info.
The active sonar from the escort would reveal the sub it is escorting to any passive observers. It would need a directional sonar (not a cheap commercial sonar) and avoiding prop noise that can also reflect off the sub.
And if all subs were escorted this way, the navies of adversaries would quickly pick up this habit.