536. Boot Hill by Sundown: The prohibition against delaying burial overnight
You shall not leave his corpse on the gallows overnight… (Deuteronomy 21:23)
Even though the convicted blasphemer or idolator was hanged after execution as a deterrent, the Torah informs us that he may not be left hanging overnight. This is because even the convicted felon deserves a decent burial. Therefore, the executed person was hanged close to sunset in order to fulfill Mitzvah #535, then taken down immediately in order to comply with our current mitzvah. (Similar to this, he was buried with the wood from which he was hanged, so that people should not make souvenirs of it.)
The Sefer HaChinuch says the reason for this mitzvah is that “a curse of God is hanged” (Deut. 21:23). Citing the mishna in Sanhedrin (6:4), he explains that displaying the corpse of the blasphemer would encourage people to talk about why he was executed, prolonging the desecration of God’s Name.
This mitzvah applies in Temple times, when capital cases are judged. It is discussed in the Talmud in tractate Sanhedrin (45b-46b) and is codified in the Mishneh Torah in the fifteenth chapter of Hilchos Sanhedrin. This mitzvah is #66 of the 365 negative mitzvos in the Rambam’s Sefer HaMitzvos.