From the website of a hat-maker:
"A gentleman should remove his hat as he enters a building, including a restaurant, home, classroom, theater, church. This rule includes baseball caps and casual hats. Hats are to be removed when inside, except for places that are akin to public streets, e.g., lobbies, corridors, and elevators in public buildings."
https://www.levinehat.com/page.....s,and%20el.
I don't cnsider myself that old (53), but my father was old-school, and wore a hat for going out with my mum. But that hat came off immediately upon entering a building. Why? Because that's what is considered polite. Yes, etiquette can change, but this aspect of it has absolutely not.
Dh and I recently spent some time just before Christmas in South Dakota, and while it was lovely, men almost universally did not remove their hats indoors or even in very nice restaurants. And I don't just mean baseball caps, but big Western hats that really, REALLY should not be worn indoors. It drove me up a wall.