The Gemara says, "Do anything a host tell you to do, except leave." A guest is obliged to obey his host, unless his host tells him to leave the home.
The commentators raise the question of why a guest is entitled to remain in someone’s home against the host’s will. Seemingly, a host reserves the right to tell his guest to leave. How can we explain the Gemara’s comment?
The Sefat Emet (Rav Yehuda Aryeh Leib Alter of Ger, 1847-1905) explains that this provision was made in response to the tragic incident of Kamsa and Bar Kamsa, which the Gemara relates in Masechet Gittin. An invitation intended for Kamsa was mistakenly delivered to Bar Kamsa, and when Bar Kamsa arrived at the party, the host forced him to leave. Bar Kamsa was very embarrassed, and decided to avenge his disgrace by going to the Roman emperor and telling him that the Jews rebelled against him, ultimately causing the destruction of Jerusalem. In response, the Sages enacted this provision that if somebody comes to a function to which he was not invited, he should not be told to leave. And if the host tells him to leave, he does not have to listen.
Thus, if a person, for whatever reason, attends a function uninvited, the host should not embarrass him by telling him to leave. We should learn the lesson taught by the tragedy of Kamsa and Bar Kamsa, and ensure not to embarrass a fellow Jew, even in a case of an uninvited guest.