I'm a daily hat wearer and hat etiquette can be complicated. (I have a "Winston Churchill" sized collection

)
Note: Non of this applies to women!
Generally if you're in a private area hat's should not be worn but if you're in a public area they can be.
For instance: The train station - Hats are OK... In someones home - Nope.
In the foyer of a building or a doctors waiting area - Again hats are OK.
- But you should remove your hat once you enter someones area/office or the doctors office.
A church is considered a "private" area so hats on when out side but as soon as you cross the threshold hat's should always be removed.
Outdoor Funerals/Graveyard: Hats are OK but they should be removed during the prayers and when the coffin is being lowered.