This is related, but not exactly. When I was growing up, it was considered to be rude and inconsiderate to wear a hat or cap inside the house, especially a house or home where you were a guest. A friend of mine told me about someone who walked into his childhood home wearing a cap, and was having a meal, with his cap on. He said his mother walked over to the person wearing the cap, removed it from his head and threw it down to the floor.
Most schools have a no hat policy, because hats can be used to signify gang membership and other nefarious things. Students of mine were mostly good about it, but I was asked about it every year. I told them that hats are used to protect the head from the elements: rain, snow, wind, and sun, and since that wasn't a problem in a building, no need for a hat.
In some ways, the thing about hats worn in a building being considered rude, is a thing of the past. I wonder how many other people were taught this or know this from years ago? It almost seems petty now.