If the commander is highly aggressive, there a chance he will surface when low on torpedoes and using deck guns. Unless you hit a mine or seriously damage beyond repair.
I know how the game works. My question has always been whether or not a particular game "mechanic" reflects reality. In the case of IJN submarines it seems that none of them ever fired torpedoes at their attackers after having been FORCED to surface because of damage
Using deck guns seems to have been the norm. It should be noted that the escorts who had depth charged the submarine to the surface got to shoot with any gun that would bear from the moment that the submarine surfaced. In most cases that was a whole bunch of guns but occasionally the submarine would surface so close to the escort that its main armament could not be depressed to bear on the submarine. In any case the result was (usually) that the submarine would be hit multiple times by relatively big guns before its gun crew had even gotten near their gun (along with a supply of ammunition). Thus it was that submarines always lost their confrontations with escorts once they were forced to the surface by depth charging/damage.
But since I checked the TROMs of all Japanese submarines (according to combinedfleet.com) and found NO INSTANCES of launching torpedoes at their attackers after being seriously damaged underwater I wondered if it had ever happened. It seems that U-371 singularly holds that honor (and although the "homing" torpedo hit it did not sink the Free French Corvette SENEGALAIS at which it was fired). Several IJN submarines were forced to the surface by damage but although they manned their deck guns (or attempted to) NONE of them fired their torpedoes.