Rules how to behave were neccessary once, when society was divided into classes. To know how to behave in a certain situation, in the presence of certain persons, gave you comfort.
Nowadays most of uns live in societies that declare (theoretically) all human beings to be equal. Everyone knows (or oght to know) there are no longer persons superior or inferior to yourself. There is no reason to be nervous about showing the right amount of respect. Therefore it is no longer neccessary to follow special rules about courtesy. But still it is important to show respect at all! I wear my sailors cap nearly allways outside. I do not take it off when greeting or talking to a lady, because only a few people still wear a hat or cap, and so it is not common practice to remove it. But for sure I give my respect by at least nodding and uttering a greeting, if not reaching out for a handshake. I feel it`s inapropriate to wear a cap inside a room, so I remove it.
But showing respect also means to accept someone other having different manners. If he does not respect me, I will recognice it whether he wears his hat or not.