21 Then all the men of his city must stone him to death. In this way you will purge wickedness from among you, and all Israel will hear about it and be afraid. 22 If a person commits a sin punishable by death and is executed, and you hang the corpse on a tree, 23 his body must not remain all night on the tree; instead you must make certain you bury him that same day, for the one who is left exposed on a tree is cursed by God. You must not defile your land that the Lord your God is giving you as an inheritance.
24 When they brought the kings out to Joshua, he summoned all the men of Israel and said to the commanders of the troops who accompanied him, “Come here and put your feet on the necks of these kings.” So they came up and put their feet on their necks. 25 Then Joshua said to them, “Don’t be afraid and don’t panic! Be strong and brave, for the Lord will do the same thing to all your enemies you fight.” 26 Then Joshua executed them and hung them on five trees. They were left hanging on the trees until evening. 27 At sunset Joshua ordered his men to take them down from the trees. They threw them into the cave where they had hidden and piled large stones over the mouth of the cave. (They remain to this very day.) 28 That day Joshua captured Makkedah and put the sword to it and its king. He annihilated everyone who lived in it; he left no survivors. He did to its king what he had done to the king of Jericho.
Notes and References
"... In my opinion, the description of impalement in Joshua 8:29 was not initially designed to illustrate Deuteronomic law, but rather takes its inspiration from the prevalent Neo-Assyrian practice directed against foreign enemies in wartime. The reliefs of the conquest of Lachish illustrate how Sennacherib carried out this practice in Judah during his third campaign. In my opinion, the early conquest account did not object to the idea that the Israelites should treat the kings of Canaan in the same fashion that Assyrians had treated Judean captives during the campaigns of the seventh century. I think that a later scribe, in the late sixth century or later, assumed that the rationale that was added to the law in Deuteronomy 21:22–23 should also apply to the period of the conquest in order to preserve the land of Israel’s inheritance from pollution. To this end, he added the details about removing the body of the king of Ai at sunset and interning his corpse in the cairn. In this case, a late Deuteronomistic revision of the Ai narrative employed the law in Deuteronomy 21:22–23 in an exegetical fashion ..."
Edenburg, Cynthia "Paradigm, Illustrative Narrative, or Midrash: The Case of Josh 7-8 and Deuteronomic/istic Law" in Berner, Christoph (ed.) The Reception of Biblical War Legislation in Narrative Contexts: Proceedings of the EABS Research Group "Law and Narrative" (pp. 163-178) De Gruyter, 2015