It's definitely a thing you don't do without good reason (enemy boarding action/mutiny) but remember subs are designed to survive nearby explosions underwater; there's redundancy and there's massive amounts of time spent training damage control where your repair or work around damaged systems.
A 9mm, buck shot, or even a 556 (which they are not using on a sub) is not piercing the pressure hull of a submarine. That's before considering all the other mass of metal and matter within the sub.
I mean, I guess there's more risk of ricochets and equipment damage on a sub than a ship? Regardless, a lot of "don't do that" things become "you might have to do that" things in a combat scenario.