Herodotus writes in The Histories that, to discourage intercourse with a corpse, ancient Egyptians left deceased beautiful women to decay for "three or four days" before giving them to the embalmers. Herodotus also alluded to suggestions that the Greek tyrant Periander had defiled the corpse of his wife, employing a metaphor: "Periander baked his bread in a cold oven." Acts of necrophilia are depicted on ceramics from the Moche culture, which reigned in northern Peru from the first to eighth century CE. A common theme in these artifacts is the masturbation of a male skeleton by a living woman. Hittite law from the 16th century BC through to the 13th century BC explicitly permitted sex with the dead. In what is now Northeast China, the ethnic Xianbei emperor Murong Xi (385–407) of the Later Yan state had intercourse with the corpse of his beloved empress Fu Xunying, after the latter was already cold and put into the coffin.In Renaissance Italy, following the reputed moral collapse brought about by the Black Death and before the Roman Inquisition of the Counter-Reformation, literature was replete with sexual references; these include necrophilia, as in the epic poem Orlando Innamorato by Matteo Maria Boiardo, first published in 1483. In a notorious modern example, American serial killer Jeffrey Dahmer was a necrophiliac. Dahmer wanted to create a sex slave who would mindlessly consent to whatever he wanted.
New Zealand
Under Section 150 of the New Zealand Crimes Act 1961, it is an offence for there to be "misconduct in respect to human remains". Subsection (b) elaborates that this applies if someone "improperly or indecently interferes with or offers indignity to any dead human body or human remains, whether buried or not". This statute is therefore applicable to sex with corpses and carries a potential two-year prison sentence, although there is no relevant case law. South Africa
Section 14 of the Criminal Law (Sexual Offences and Related Matters) Amendment Act, 2007 prohibits the commission of a sexual act with a corpse. Until codified by the act it was a common law offence. Sweden
Section 16, § 10 of the Swedish Penal Code criminalises necrophilia, but it is not explicitly mentioned. Necrophilia falls under the regulations against abusing a corpse or grave (Brott mot griftefrid), which carries a maximum sentence of two years in prison. One person has been convicted of necrophilia. He was sentenced to psychiatric care for that and other crimes, including arson. United Kingdom
Sexual penetration of a corpse was made illegal under the Sexual Offences Act 2003, carrying a maximum sentence of two years imprisonment. Prior to 2003, necrophilia was not illegal; however, exposing a naked corpse in public was classed as a public nuisance (R v. Clark [1883] 15 Cox 171). United States
There is no federal legislation specifically barring sex with a corpse.