This has very little to do with religion. It is an aspect of Afghan culture.
According to the culture and traditions of Afghanistan, if a man is escaping and he hides in another man's house for protection, the man in whose house he is hiding must protect him from outsiders, and must even fight to the death if necessary.
To take an extreme case, let us say that a man has killed several people and the families of the men he has killed are chasing him. The fleeing man then runs into the house of a stranger.
When the mob who is chasing the killer arrives at the house, the owner of the house is required to defend and protect his unwanted guest from the outsiders. This applies even if the man in whose house he is hiding is friends or even relatives of the members of the mob that is chasing him.
Everybody familiar with the culture of Afghanistan knows this. Osama bin Laden obviously knows it too. He is relying on this custom of Afghanistan to protect him from the USA, even though he knows that most Afghans do not want him in their country.