The habit of killing bad criminals by hanging them on trees is a very archaic one. It was originally practiced as a sacrifice: Germans in olden days, for instance, hanged prisoners as sacrifices to the god Wotan.
Von Franz establishes the gallows as a site of archaic sacrificial practice, linking execution by hanging directly to the cult of Wotan and the Indo-European mythology of the suspended god.
, Shadow and Evil in Fairy Tales, 1974thesis