Going to the stall creates a sort of dilemma for an armed person - officer or civilian. Where do you leave your pistol(s) when you are sitting on the throne? Think about it.
Lots of things can be done. I actually talk about this when I teach my carry class. Let's face it: While carrying, students are much more likely to go to the bathroom than to draw their guns.
A cop wearing a duty belt will have a retention holster. A gun grab is unlikely under the stall door with one of those.
A cop or carry permit holder in street clothes has many choices:
If wearing a belt holster (IWB or OWB), leave the gun in the holster, and arrange your pants to cover the gun as it sits on your pants between your ankles.
Alternately, lower your pants and re-fasten your belt. Hold your calves apart to keep the belt taut.
If you are worried that your holster will dump the gun... well, get a better holster.
If you must remove the gun from the holster, placing it in the underwear is a perfectly acceptable idea.
If you forget it there and yank up your pants quickly you could have a pistol/private parts collision and that could be disastrous.
Nah.
If you carry in a shoulder holster, a belly band, an ankle holster, a SmartCarry/Thunderwear holster, you're all set.
Removing the gun and placing it on the TP or on the toilet tank is NEVER a good idea, as law enforcement types have repeatedly demonstrated.