All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
In principle, it is forbidden to transgress a Muslim. This is a well-established principle in the Sharee’ah. Similarly, the rights of the Muslim must not be violated regardless of whether he is alive or dead.
‘Aa’ishah narrated that the Prophet said: “Breaking the bone of the dead is the same as breaking the bone of the living.” [Abu Daawood and Ibn Maajah]
Ibn Hajar said: “This means that the sacredness (inviolability) of the believer remains the same after his death as it was during his life.” But the rulings of the Sharee’ah call for getting the benefits while avoiding the shortcomings. This is why many Muslim scholars permit opening the belly of the dead pregnant woman to take out her living fetus. They also permit cutting the fetus into pieces if there is no other way to save his mother who will die otherwise. Some scholars even permit eating the flesh of dead human beings for dire necessity. Ibn As-Subki stated in his introduction about al-Muzni that the soundest opinion in the Shaafi’i School of jurisprudence is that 'It is lawful for the person in dire necessity to eat the flesh of the dead human being.'
Therefore, it is lawful to anatomize or dissect the corpse of the dead person regardless of his age for medical purposes. The reason for this is that the purpose behind studying medicine is to save the lives of the sick and this is a dire necessity. The purpose can also be to relieve the pain of the sick and this is a necessity of lesser degree. As for violating the immunity of the dead, this is disregarded in this case, as the aim here is to achieve the most important of the two benefits. It is a common ruling in the Sharee’ah that if two benefits are conflicting, the most important of them is given priority over the least important, and if there is conflict between two disadvantages, the least of them is given priority as to avoid the worst.
In addition, the benefit from treating the disease and acquiring safety is a common benefit while avoiding anatomizing the dead body is peculiar to that person only. It becomes then obligatory to give priority to the common benefit over the individual one which is not well established. No doubt also that parrying the harm from inflicting a living person is more important than parrying the harm from a dead person when both benefits are conflicting. Moreover, learning medicine is a common obligation on the Muslim Ummah and doing so nowadays requires learning anatomy and other medical branches. The Sharee’ah stipulates that anything which is needed to fulfill an Islamic obligation becomes obligatory as well.
But if there is a corpse of a disbelieving person that can be used for the purpose of learning, or if there could be some teaching aids for anatomy without having to use a corpse, then it becomes unlawful to use the Muslim's corpse in anatomy as necessity is valued according to its proper value.
Similar Fataawa to the one above have been issued by the council of the senior scholars in Saudi Arabia in its ninth session from its decision No. 4796 dated 13/08/1420; as well as by the Islamic Fiqh Assembly in Makkah in 1408 and Al-Azhar Fatwa section in Egypt 29/02/1971.
For more benefit on organ donation and its conditions, please refer to Fataawa 86647, 85514, and 323434.
Allah knows best.