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.
Of course, other aspects of other missions might also require firearms.
And since they have fucking nukes, all possible scales of violence are literally on the table.