
It is said that when Joshua entered the Land he met a man and bowed down to him. “When Joshua was by Jericho, he lifted his eyes and looked, and behold, a Man stood opposite him with His sword drawn in His hand. And Joshua went to Him and said to Him, ‘Are You for us or for our adversaries?’ So He said, ‘No, but as Commander of the army of the Lord I have now come.’ And Joshua fell on his face to the earth and worshiped.” (Joshua 5:13-14). The scholars asked: How could Joshua have bowed to a man he did not know, in contradiction to the rule that a person is forbidden to greet a person he meets by chance at night, lest the “person” be a demon who could harm him? Answer: It was clear to Joshua that this was not a demon but a real person, for the person introduced himself and said “As Commander of the army of the Lord I have now come.” The scholars then asked: Perhaps the demon lied and said that he was commander of the army of the Lord though he was truly a demon? Answer: Demons do not utter the name of the Lord in vain and would certainly not pretend to be the as commander of the army of the Lord.
(Babylonian Talmud, Tractate Megillah 3a)