"The tradition of men removing their hats indoors is thought to date back to the practice of medieval knights removing their helmets when entering a building as a signal of friendly intent."
Seems a bit outdated.
I got banned on another web site for a debate that happened on this site. That's a first