The public execution of a defeated enemy leader serves as a powerful psychological tool during war. It sends a clear message of absolute victory while maintaining strict moral boundaries regarding the treatment of the dead. Capturing a king alive during battle is a rare event, as rulers typically flee or die in the midst of combat.
When the king of Ai was captured alive, Joshua seized the opportunity to hang him on a tree where he could be seen from a great distance. This public display served a dual purpose. It brought a sense of joy to the Israelites to see their enemy defeated, while simultaneously breaking the spirit of the opposing forces, who had to watch their elevated ruler hang like a commoner [אברבנאל].
As evening approached and the sun set [ביאור שטיינזלץ], the king's body was taken down. This was done before nightfall to fulfill the biblical commandment against leaving a corpse hanging overnight. While one might assume this rule applied only to deceased Israelites, it actually extends to anyone executed within the Land of Israel [רד״ק]. Joshua strictly observed this law to ensure the land would not be defiled [אברבנאל].
Beyond the religious requirement, there was also a practical, hygienic reason for removing the body: to prevent the air from becoming foul [רלב״ג]. Although the human body is the most dignified and elevated of all living creatures during life, it completely loses this status in death. A human corpse rots and produces a foul odor much faster than an animal carcass, making immediate burial a necessity [אברבנאל].
Once removed from the tree, the body was thrown at the entrance of the city gate, and a massive pile of stones was erected over it. This pile acted as a prominent marker indicating the burial site of the city's king [אברבנאל]. The primary purpose of this stone monument was to publicize the defeat, ensuring that the other idol-worshiping kings in the region would see it, become gripped with fear, and be deterred from waging war against the Israelites [רלב״ג, אברבנאל].