I mean, sure, it creates a bit of an instinctual reminder to put something on your head when you go outside, so it's helpful, but that doesn't mean that was the original rationale, especially when the same regulations apply to guys who spend their days staring at a radar scope in CIC or something. And let's be honest, lots of military traditions are kind of arbitrary (like the part where if you're walking with someone, the senior ranking person is on the right hand side--what, do you get shot at more often from the left hand side?) Having to adapt to a bunch of arbitrary traditions might have some benefit in discipline or something, but each individual tradition isn't necessarily there for a practical reason. Especially when a bunch of those traditions are actively dropped in combat zones--i.e. you don't salute so they don't know who to shoot at.
It is dubious, but I wouldn't absolutely rule out the hat edict as having a purpose. Remembering to wear something on your head is definitely an acquirable muscle memory.
> like the part where if you're walking with someone, the senior ranking person is on the right hand side--what, do you get shot at more often from the left hand side?
This example, on the other hand, probably is the result of conscious, practical decision making. You are better positioned with your sword arm free. It seems reasonable that the senior ranking person would insist on walking on the side that allowed them to have their sword arm (pistol arm) free in case of attack.
You can build a ramp around a tower in two ways. One direction puts your right hand on the side open to the air. The other pins it against the tower wall. Towers were built so that the direction of the ramps encircling them allowed defenders at the top to have their sword arms free to the open air. Attackers coming up with the ramp would have their sword arms inhibited by the face of the tower. You can verify this by inspecting the construction of the towers.