In Greek thought, there was even a specific term for showing hospitality to a guest: xenia (ξενία). If a host harmed his guest, Zeus would avenge them. This went both ways, too. In Homer's epic The Odyssey, book 21, we are told the major sin of the suitors is that they abused hospitality.
In the Assyrian Words of Ahiqar, Ahiqar provides hospitality to a man wanted dead by Sennacherib, saying he treated him as a 'brother'. The Babylonian Counsels of Wisdom summarized sacred hospitality as:
Give food to eat, beer to drink,
Grant what is asked, provide for and honour.
In this a man's god takes pleasure,
It is pleasing to Shamash, who will repay him with favour.
Do charitable deeds, render service all your days.
Within Israelite thought, Leviticus also instructs the people to show hospitality to foreigners and travelers:
When a stranger sojourns with you in your land, you shall not do him wrong. You shall treat the stranger who sojourns with you as the native among you, and you shall love him as yourself, for you were strangers in the land of Egypt: I am the LORD your God. (Leviticus 19.33-34, ESV translation)
In Job's self-defense against accusations, he mentions his hospitality:
"No stranger ever spent the night in the street, because I opened my doors to travelers." (Job 31.32, ISV translation)
The concept of 'sacred hospitality' was widespread throughout Indo-European cultures. Violating expectations of hospitality was seen to be so severe, divine protection or vengeance was regularly attributed to this or that deity.
When we read Genesis 19, it appears that Lot did not initially recognize that they were angels. Lot's motivations should be read in context with all of Genesis 18 as well:
- Three messengers from God show up to Abraham. Abraham knows something is up by their sudden appearance, but he immediately shows hospitality to them. He instructs Sarah to prepare a full meal for them (and given what the meal consists of, probably took a better part of the day to prepare).
- God, via the lead of these three messengers, informs Abraham that he is going to test Sodom and Gomorrah, and if the cities do not check out as righteous they will be destroyed. Abraham negotiates with God to spare the city if even ten righteous people are found in them.
- The other two messengers travel to Sodom, and Lot immediately shows hospitality to them, while the rest of the men of the city attempt to force themselves on the messengers.
In the present context, 'righteousness' is highlighted by hospitality. Both Abraham and Lot show hospitality to the mysterious travelers, no questions asked. Meanwhile, the people of Sodom not only fail to show hospitality, they're outright hostile.
From J.W. Jipp, Divine Visitation and Hospitality to Strangers in Luke-Acts, p. 136-139:
With the scene set as a divine visit of inspection in response to rumors of Sodom's injustice, "the two messengers/angels" come to Sodom "in the evening" and encounter Lot who is sitting at the gate of Sodom (19:1). Lot responds to their presence with proper hospitality. The messengers' initial resistance to Lot's invitation should not be understood as an attempt to reject shoddy hospitality but, rather, as a test "designed to judge whether his offer is purely perfunctory or genuine." The parallels between Abraham's and Lot's hospitable response to the messenger is obvious:
. . .
As with Abraham, there is no indication that Lot immediately recognizes the divine identity of his visitors.
. . .
One of the perplexing features of Lot's hospitality, however, is that the responsibility for welcoming strangers ought to have been practiced by citizens of the city whereas Lot is himself a "resident alien" (19:9). Has Lot, then, committed a transgression by welcoming these visitors? The answer is negative, for the story indicates that not one citizen of Sodom practices hospitality to strangers.
In other words, in context, the whole premise of God's test on the cities was how their residents would treat these seemingly random travelers. The point was that the cities were to show these men hospitality regardless of their anonymity. The irony is that a foreigner (Lot) showed hospitality, while the native citizens of Sodom showed hostility.
Neither Lot nor the people of Sodom had any reason to assume the two 'men' were something other than foreign travelers. None of them knew they were interacting with angels until Sodom had already failed the test.