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 rest 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.
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.
Lot assumed the men were travelers; he didn't know they were angels.