In the United States and many other developed nations, it is rude to wear a hat indoors due to basic social etiquette. Hats are typically removed inside buildings, but they are also removed for Christian church events, weddings, funerals and other special occasions.
Hats were often worn for protection from the sun and industrial activities. Men generally "tipped" their hats, or temporarily removed them, in the presence of women as a sign of good manners and respect. This developed into removing one's hat when indoors as a sign of respect and trust. There were also valid safety reasons for wearing a hat most of the time when outdoors. While wearing hats often is not as common now, removing one's hat inside a home or building is still considered good etiquette.