Necrophilia in Islam
This article looks at how Islam views necrophilia.
There doesn't seem to be any verse supporting or denouncing necrophilia. There are some general rules, to be "just" and "don't commit bad deeds", but since pedophilia in Islam is ok, we can't be sure necrophilia isn't.
Unlike the prohibition on pork, a prohibition on necrophilia was NOT mentioned in the Quran. It's worth nothing that there is a verse telling Muslims not to say something is haram, when Allah did not make it haram:
And do not say about what your tongues assert of untruth, "This is lawful and this is unlawful," to invent falsehood about Allah . Indeed, those who invent falsehood about Allah will not succeed.
Ibn Kathir explains the verse as such:
(And do not describe what your tongues have lied about, saying: "This is lawful and this is forbidden", to invent lies against Allah.) This includes everyone who comes up with an innovation (Bid`ah) for which he has no evidence from the Shari`ah, or whoever declares something lawful that Allah has forbidden, or whoever declares something unlawful that Allah has permitted, only because it suits his opinions or whim to do so.
So claiming that necrophilia is haram could be considered a bid'ah (innovation), which is a sin in Islam.
There are some hadiths that some people interpreted as condoning pedophilia:
Narrated Anas bin Malik:
We were (in the funeral procession) of one of the daughters of the Prophet (ﷺ) and he was sitting by the side of the grave (جَالِسٌ عَلَى الْقَبْرِ - literally "sitting on the grave"). I saw his eyes shedding tears. He said, "Is there anyone among you who did not have sexual relations with his wife last night?" Abu Talha replied in the affirmative (أَنَا - literally "me!"). And so the Prophet told him to get down in the grave. And so he got down (فَنَزَلَ) in her grave.
So Muhammad sits on her grave, then asks his companions if any of them didn't have sex with his wife last night, Abu Talha says "me!" and then Muhammad tells him to get down to her grave. According to apologetics, he went there to bury her. The hadith says he went down there, but it doesn't say what he did there, so it's not clear.
There is also this hadith, but from a weaker source:
“I (Muhammad) put on her my shirt that she may wear the clothes of heaven, and I SLEPT with her (واضطجع معها) in her coffin (grave) that I may lessen the pressure of the grave. She was the best of Allah’s creatures to me after Abu Talib”… The prophet was referring to Fatima, the mother of Ali.
There is a discussion about the word "واضطجع", whether it means sleeping or lying or having sex, but the next word معها ("with her") makes that discussion not important. Because even if he was just lying there, it was "with her", which is controversial enough. But apologists can dismiss the whole hadith as unreliable.
So the first hadith is authentic, but doesn't clearly support necrophilia, while the other hadith supports necrophilia, but is not very authentic. We could discuss about these pro-necrophilia hadiths, but maybe it's even more important to notice that there is no hadith explicitly prohibiting necrophilia. So even if the first one didn't mean necrophilia and the other was fabricated, there is still no basis for claiming necrophilia is haram.
Views of Islamic scholars
Since the Quran and sunna don't condemn necrophilia and Islamic scholars base their morality on Islam, their views towards necrophilia are tolerant:
ولا يعاد غسل الميت إذا أولج فيه لسقوط تكليفه ولا يجب بوطء الميتة حد ولا مهر
A dead body need not be washed after you have sexual intercourse with her
You just have to wash your penis:
ولو غيب الحشفة في دبر امرأة او دبر رجل او فرج بهيمة او دبرها وجب الغسل سواء كان المولج فية حيا او ميتا صغيرا او كبيرا
If the male genitalia completely entered a woman's behind, or a mans behind or a baheema(animal) from behind or vagina, he must be washed wether it was alive or dead (ميتا), young or old