Unlike today, in the past anyone could come to Versailles, no admission fee required. Everyone…, close to everyone…, everyone, except for the monks and the beggars; yes, even the pickpockets and prostitutes were welcome, provided they were discrete. For a woman to be at Versailles all she needed was a man by her side; as for a man all he needed was a hat and a sword; and if he had none, they would rent them to him in the lobby. Once the sword was attached, the Hundred Swiss would address the fellow as Marquis, and it didn’t matter what his real title was, or if he had one, it was just like saying Sir. That’s why that sword was a must. As for a hat, it was a little more important, because the hat etiquette was complex!
We could say that there were two kinds of people at Versailles, those who kept their hats in the presence of the monarch, and then the rest. By the rest we mean all the other courtiers, because below the princes of blood and dukes, everyone was on equal footing. Outside of Versailles things could be different; for example, if the king was with the army — in the military camp, the whole hat thing was off, or rather applied very differently; and when he went to Marly, that palace being so small, he was considered as a private individual; so those who came along were his guests, and did not need to observe the etiquette; and even at Versailles, if His Majesty was throwing a party, or sat down at the cards table, this meant that no salute was required. You got the idea. Roughly, when he puts the hat on, you take it off, when he takes it off, you should put it on. But all this is just for the country bumpkins who do not know better. A real courtier was well versed in this matter, which distinguished him from a visitor!
Why would the King take the hat off? The king had his hat off in the presence of other princes, even if they traveled incognito, but incognito means private, and in private everyone is prince. Receiving the Dodge of Venice would be a different case, and a good example: The Dodge had to bear his head approaching Louis XIV, but Louis would be one step ahead, he had been waiting for this ambassadorial procession already bareheaded; so, the Dodge could interpret this as the ultimate sign of respect, all be it with a small degree of reservation: I respect you, but I do not exactly remove my hat in your presence! Yes, we are equal, but you come to me; so, what do you want? The only time the King explicitly removed his hat as a mark of respect was in the presence of a woman, any woman, even the humblest room servant.