14 Now the Lord raised up an adversary against Solomon, Hadad the Edomite; he was a descendant of the king in Edom. 15 For it happened, when David was in Edom, and Joab the commander of the army had gone up to bury the slain, after he had killed every male in Edom 16 (because for six months Joab remained there with all Israel, until he had cut down every male in Edom), 17 that Hadad fled to go to Egypt, he and certain Edomites of his father’s servants with him. Hadad was still a little child. 18 Then they arose from Midian and came to Paran; and they took men with them from Paran and came to Egypt, to Pharaoh king of Egypt, who gave him a house, apportioned food for him, and gave him land. 19 And Hadad found great favor in the sight of Pharaoh, so that he gave him as wife the sister of his own wife, that is, the sister of Queen Tahpenes. 20 Then the sister of Tahpenes bore him Genubath his son, whom Tahpenes weaned in Pharaoh’s house. And Genubath was in Pharaoh’s household among the sons of Pharaoh.
argues that this is due to different possible spelling in Deuteronomy. Not sure what. The Deuteronomy talks about erasing memory of Amalek rather than Edomites. Yoab think that it means killing all the males. Yoab then kill the rabbi that taught him incorrectly.