I was taught in the military that you don’t remove your hat while indoors if you’re under arms.
And that is correct.
Otherwise, what would you do with your hat/cap/helmet/cover if you had to employ your weapon?
No part of your uniform is immaterial.
Every action taken should be executed with continuity and fluidity of motion considered beforehand.
Looking around for a suitable place of storage for your hat/cap/helmet/cover is not conducive to continuity and fluidity of motion.
(What the hell else kinda answer would an old retired Sergeant Major give you, anyway?)