Earlier when David was fighting with Edom, Joab the commander of the army, who had gone up to bury the dead, had struck down all the men in Edom.1
References for 1 Kings 11:15
Joab and all the Israelites stayed there for six months, until they had destroyed all the men in Edom.
But Hadad, still only a boy, fled to Egypt with some Edomite officials who had served his father.
They set out from Midian and went to Paran.2 Then taking men from Paran with them, they went to Egypt, to Pharaoh king of Egypt, who gave Hadad a house and land and provided him with food.
References for 1 Kings 11:18
Pharaoh was so pleased with Hadad that he gave him a sister of his own wife, Queen Tahpenes, in marriage.
The sister of Tahpenes bore him a son named Genubath, whom Tahpenes brought up in the royal palace. There Genubath lived with Pharaoh's own children.
While he was in Egypt, Hadad heard that David rested with his fathers and that Joab the commander of the army was also dead. Then Hadad said to Pharaoh, "Let me go, that I may return to my own country."
"What have you lacked here that you want to go back to your own country?" Pharaoh asked. "Nothing," Hadad replied, "but do let me go!"