The human body is sacred in Islam, while alive and after death, Muslim or non-Muslim. Cutting up or tampering with a dead body is prohibited and considered dishonoring it. So unless there is a need, and proper protocols of covering the private parts are observed, it is not allowed. A case of genuine need is when the operation will help identify a criminal, when it is needed for medical research that cannot be accomplished through another method (though a similar objective can often be obtained by using animal or artificial bodies), or when forced by law, despite protest, to have it done.
For doctors, if it is a legal requirement to carry out these procedures then they may perform them since they cannot opt out. For medical students, if they cannot obtain a solid education elsewhere, then it would be allowed as well since medical knowledge is a need in every community.
What the Qur’an and Sunnah Say
Allah said, “Indeed, we have honored the children of Adam.” (Surah al-Isra, 70)
The Messenger of Allah said: “Breaking the bone of a dead person is similar (in sin) to breaking the bone of a living person”. (Abu Dawud, Ibn Majah, Ahmad)
What the Scholars Said
Imam Kasani states: “If a pregnant woman died with her child trapped in her stomach, then if it is thought the child will be alive, her stomach will be cut open, because we have been faced with two evils and we are choosing the lesser of the two. Cutting open the dead mother’s stomach is lesser of an evil than killing the living baby.” (Bada’i as-Sana’i, 5:129)
Imam Ibn Humam states: A person unjustifiably and unlawfully swallowed a precious item, like a gemstone, of another person and then died. If the one whose precious item he swallowed demands compensation, then if the deceased person left some money behind, it will be paid from his leftover wealth. However, if he left nothing behind, his body will be cut open and the precious stone or item will be removed from him and returned to its owner. (Fath al-Qadir)
Shaykh Mustafa Umar