I've recently re-read Clancy's "Red Storm Rising", the sections on submarine (and anti-) warfare are really interesting (I understand some of it may be simplified/fictional). E.g., how the Mark 48 torpedo can be set to and launched in "hunting mode", where it circles at a slow, undetectable speed, and only after acquiring a target it suddenly accelerates for a kill.
Let's consider this excerpt from [1]:
Terminal Homing is the final stage of the torpedo attack. (...) Terminal homing is an active sonar ping that retransmits on reception becoming more rapid as the range to target closes at maximum speed. (...) The target is alerted to the attack, but there is nothing it can do to defeat the weapon at this point. The weapon is too close and moving too fast to allow time for a countermeasure to be effective.
Now, I might have read too much David Weber ([2]), but wouldn't a small, cheap-ish counter-torpedo suffice? Put 10-20 of them in small automated launchers all around the hull, and let them crash head-on with the (now perfectly detectable) approaching boat-killer, still at a safe distance (which is.. I don't know, 100-200 m?)
[1] https://www.thedrive.com/the-war-zone/33018/modern-submarine...