Best advice is to stay out of harbours in bad weather. You run the risk of broaching your conning tower and giving away the surprise. Wait until the weather improves before entering the harbour and you should see fewer self sinking ships. Unfortunately SH3 ships have a natural drift which is worsened with heavy seas and they tend to smash themselves against the wharves or each other if they are close enough.
For more hints of the process of getting into and out of the enemies lair safely :
http://www.subsim.com/radioroom/showthread.php?t=96843