Indoors, a man should always remove his hat, (particularly in a home, church, courtroom or restaurant) except:
(1) in some public buildings or public places such as railroad stations or post offices;
(2) in the main parlor area of a saloon or general store;
(3) or while seated at the "lunch counter" of a diner or cafe;
(4) in entrance halls and corridors of office buildings, or hotels;
(5) in elevators of public or office buildings, unless a woman is present;
(6) if carrying packages, parcels or bags and both hands are occupied upon entry.
(7) If the man is an actor or performer and the hat is being worn as a part of a costume or performance.
If in doubt, it is best for a gentleman to remove his hat indoors as soon as practical.
It is considered a sign of contempt and/or disrespect to leave your hat on when it would be proper to remove it.