Should a man take off his hat in public restaurants or other indoor places? I was amazed at how angry my father-in-law became when my son wore his baseball cap inside a restaurant.
Another time, I had a professor throw a kid permanently out of class after she told him six different times to take his hat off.
I asked both of them why? They told me that it is a sign of respect. In the military, your rank is determined by your hat. So if an officer goes into a bar, or restaurant all the people of lesser would have to salute him, or her, so he removes his hat.
That is wear the tradition comes from.