If one is to be given a death sentence by court, then can he give consent for donation of his/her organs before or after death?
(Question published as received)
In the name of Allāh, the Most Gracious, the Most Merciful
As-salāmu ‘alaykum wa-raḥmatullāhi wa-barakātuh
The issue of organ transplants has been discussed in much detail by contemporary Ulama and Muftis. In doing so the counsel of medical experts was sought and the practical realities were considered. Here are two important issues in organ transplants.
1. The honour and respect of the human body
2. Medical need
The human body is sacred and deserves utmost respect and honour. However, unfortunately we are living in sad times that people have no respect for the human body and have even commercialised the human body.
Human body trafficking and organ sales is on the rise and is an organised crime, involving a host of offenders. The recruiter who identifies the vulnerable person, the transporter, the staff of the hospital, clinic and other medical centres, the medical professionals, the middlemen and contractors, the buyers, the banks where organs are stored are all involved in the racket .
According to the World Health Organization (WHO), illegal organ trade occurs when organs are removed from the body for the purpose of commercial transactions. The WHO justifies these actions by stating that, “Payment for…organs is likely to take unfair advantage of the poorest and most vulnerable groups, undermines altruistic donation and leads to profiteering and human trafficking.” Despite these ordinances, it was estimated that 5% of all organ recipients engaged in commercial organ transplant in 2005. Research indicates that illegal organ trade is on the rise, with a recent report by Global Financial Integrity estimating that the illegal organ trade generates profits between $600 million and $1.2 billion per year with a span over many countries .
While we understand the medical need for organ transplant, the need to uphold human respect and honour is more important. It is for this reason and the unfortunate commercialisation of the human body as well as other possible negative consequences, the Muftis and Ulama have ruled the following: 
It is permissible to accept an organ from a living individual with the following conditions:
1. The donor’s life is not endangered by donating the organ,
2. The donor donates willingly,
3. The only solution to the sickness is through donating the organ. 
It is not permissible for a person to bequeath ones organs after death.
And Allah Ta‘ālā Knows Best
(Mufti) Bilal al-Mahmudi
Checked and Approved by,
Mufti Ebrahim Desai
You may also see:
 http://www.ungift.org/knowledgehub/en/about/trafficking-for-organ-trade.html https://en.wikipedia.org/wiki/Organ_trade  Jawaahirul Fiqh V 7 (Maktabah Darul Uloom Karachi)
فالضرورة: بلوغه حدا إن لم يتناول الممنوع ،هلك أو قارب، وهذا يبيح تناول الحرام الحاجة: كالجائع الذى لو لم يجد ما يأكله لم يهلك غير أنه يكون فى جهد ومشقة، وهذا لا يبيح الحرام، ويبيح الفطر فى الصوم. (شرح الحموى على الاشباه والنظائر ج ١. ص ٢٥٢. ادارة القران والعلوم الاسلاميه) Taken from the Urdu translation ‘Fiqhi Faislay’ p. 157