That's a known bug that has already been reported (and ignored by AGSI):
Sub sinks itself
http://tinyurl.com/3efezwj
Sub sinks itself while firing torpedoes at ship
There are ways you can try to mitigate the problem. For example, before I fire a torpedo like that, I order the ship/sub to stop (0 kts) so that my own acoustic signature is minimized. Sometimes, this works and the torpedo goes in the correct direction. Once the torpedo has cleared the ship/sub (and hopefully locked onto the correct target), I then increase speed and evade.