A post-mortem erection or a death erection is called a priapism, sometimes it's referred to as angel lust. The death stiffy has been noted in the corpses of human males who have been executed, particularly by hanging.
Zombie boners have been attributed to pressure on the cerebellum created by the hangmans noose. Injuries to the cerebellum or spinal cord are often associated with priapism in living patients. Death by hanging, whether an execution or a suicide, has been observed to affect the genitals of both men and women and can often include discharge.
Other causes of death may also result in a woody corpse, including fatal gunshot wounds to the brain, damage to major blood vessels, and violent death by poisoning. A post-mortem hard on is an indicator that death was likely swift and violent, however, it can occur through blood settling in a cadaver that is face down.
See you don't have to be Lazarus to get up after death.