To make sure the torpedo will go boom you must:
1. Fire from at least 300m away (better still 400+ meters)
2. make sure your Angle of the Bow (AOB) is around 90deg (give or take 10-15deg).
3. If you're using magnetic pistols (M) fire 0.5m under the keel of the ship but remember that bad weather conditions can affect the shot.
4. Make sure your gyro-angle is small (around 5deg max-better still 0deg) This can be seen in the periscope screen when you're about to fire. There is a small triangle there, if it's green you're OK, if it's yellow you might still hit to ship but it's more difficult and if it's red forget about it.
5. Make sure you set the correct running depths for your torpedoes. Don't hit the ships too low on their draft as they tend to be more curvy in that area and the torpedoes might bounce off.
Good Luck