Legality
Australia
Necrophilia is not explicitly mentioned in Australian law; however, under the Crimes Act 1900 – Sect 81C, penalised for misconduct with regard to corpses is any person who:(a) indecently interferes with any dead human body, or
(b) improperly interferes with, or offers any indignity to, any dead human body or human remains (whether buried or not), and

shall be liable to imprisonment for two years. Brazil
Article 212 of the Brazilian Penal Code (federal Decree-Law No 2.848) states as follows:
Art. 212 – To abuse a cadaver or its ashes:Penalty: detention, from 1 to 3 years, plus fine. Although sex with a corpse is not explicitly mentioned, a person who has sex with a corpse may be convicted of a crime under the above Article. The legal asset protected by such Article is not the corpses objective honour, but the feeling of good memories, respect, and veneration that living people keep about the deceased person: these persons are considered passive subjects of the corpses violation. India
Section 297 of the Indian Penal Code entitled "Trespassing on burial places, etc.
Necrophilia, also known as necrophilism, necrolagnia, necrocoitus, necrochlesis, and thanatophilia, is sexual attraction towards or a sexual act involving corpses. It is classified as a paraphilia by the World Health Organization (WHO) in its International Classification of Diseases (ICD) diagnostic manual, as well as by the American Psychiatric Association in its Diagnostic and Statistical Manual (DSM). Origins of term
Various terms for the crime of corpse-violation animate sixteenth- through nineteenth-century works on law and legal medicine. The plural term "nécrophiles" was coined by Belgian physician Joseph Guislain in his lecture series, Leçons Orales Sur Les Phrénopathies, given around 1850, about the contemporary necrophiliac François Bertrand:
It is within the category of the destructive madmen [aliénés destructeurs] that one needs to situate certain patients to whom I would like to give the name of necrophiliacs [nécrophiles]. The alienists have adopted, as a new form, the case of Sergeant Bertrand, the disinterrer of cadavers on whom all the newspapers have recently reported. However, dont think that we are dealing here with a form of phrenopathy which appears for the first time. The ancients, in speaking about lycanthropy, have cited examples to which one can more or less relate the case which has just now attracted the public attention so strongly. Psychiatrist Bénédict Morel popularised the term about a decade later when discussing Bertrand. History
In the ancient world, sailors returning corpses to their home country were often accused of necrophilia. Singular accounts of necrophilia in history are sporadic, though written records suggest the practice was present within Ancient Egypt.