There are sonar decoys. They aren't easy.
You also have to have it rigged ready to go with very little notice.
The other aspect is that these torpedoes can still be wired to the ship so you can continue to use the host sub's arguably better passive sonar systems and let the attacking torpedo get VERY close.
As with all things in submersible conflict the first person to be heard is dead.
The other aspect of your decoy system that you might not be thinking about is that you've a) compromised the hull with holes b) you are going to make a LOT of noise firing those off c) your sonar signature might go up dramatically when the doors are opened etc.
The hull actually has something similar to stealth coating (but for sonar, so easier to develop cuz it's against sound waves) on the hull. You really don't want to mess with it too much.
Sub warfare is insane. There isn't really a strong counter to them in the open ocean. USN Carrier groups are especially vulnerable (at least from exercises I've read about).
Your idea isn't bad. Just make it a towed array that pops off a bunch of really loud shit 1000m behind you or something.
This would eventually turn into a cat/mouse game of who can make a better system for detecting decoys vs fooling torpedoes.
If you read up on china's new hypersonic missile system you can get a feeling for why this shit is terrifying sometimes. Fractional Orbital Bombardment System is new and very scary for the USA missile defense systems. They effectively shrink the "we can see it range" down to a very small amount of time to respond. Combine that with MIRV warheads and decoys and it's a nightmare.