Unfortunately, for equality, most hat etiquette is intended for the man. The reason for this is that men’s hats are easily removed. Women’s hats traditionally were very fussy and actually attached to their hair with hat pins and the like. Taking it off would also often mess up their hair dos. However, when a woman wears a gender-neutral hat like a baseball cap, she needs to also remove it when indoors. I would count warm winter hats as well, but you’re probably taking those off indoors already.
Interestingly, a hostess does not wear a hat in her own home. So if a woman were hosting a luncheon, bridge game, bridal shower, etc. in her home during the afternoon (in ye olden times) all of her female guests would probably be wearing hats, but she would not. Women did not wear hats with a brim after 5pm, they switched to cocktail hats which were much smaller.
An interesting exception to women keeping their hats on inside was when attending the theater. If one’s hat was so big as to obscure the view for someone behind them, the person who was being blocked could ask that the hat be removed and it should be done at once. It would be wise to wear only very small hats to the theater, obviously. Men took off their top hats when seated for the performance (collapsible top hats were made for this very purpose!) but they kept them on when strolling the corridors.
There is an exception to taking your hat off indoors. When you enter a public building and are using transitional spaces such as lobbies, hallways, and elevators, you do not need to take your hat off. Do take it off once you reach the office/apartment/whatever you are visiting. Hats remain on on public transportation and in stores as well. Hats are removed in restaurants (except when sitting at a counter in an informal restaurant).
In addition to indoors, hats need to be removed for the national anthem and passing funeral processions.
In some religious spaces, such as some Jewish synagogues, it might be required that men cover their heads. Go with what is done.
Traditionally, men spent a lot of time doffing their hats or tipping the brim. A man would remove his hat when meeting a woman in the street and stopping to talk with her. He would also take it off when a woman entered an elevator he was in. A man would briefly lift his hat or touch the brim when: greeting strangers on the street, after briefly speaking to a strange woman (after informing her of a dropped object, for example), when passing a woman in a tight space, to acknowledge a kindness or favor in public, or basically anytime he needed to acknowledge a stranger in public.