‘Finally, on the question of fluidity of gender identity, in one sense the shariah’s stance is quite progressive. Based on the Qur’anic verse that includes “those who have no desire” (Qur’an 24:31) among those categories of men around whom women do not have to wear hijab, and on the authentic hadiths that describe the Prophet ﷺ allowing an effeminate male (mukhannath) to sit in private with the women of his household, Muslim scholars concluded that there was no sin or punishment for a male who was naturally effeminate (or a female who was naturally masculine in her mannerisms), provided that he or she was not actively affecting this behavior. Scholars differed on a related question. One position, advocated by Imam al-Nawawī (d. 1277), held that, because “this is the nature (khilqa) in which God created him,” an effeminate male/masculine female was not required to alter their behavior. A second position held that such a person should still do their best to change their mannerisms. This second stance was advocated by al-Munāwī (d. 1622) and Ibn Ḥajar (d. 1449), who nonetheless excused those people who were unable to change their mannerisms even after trying their best.
The case of someone trying to take on the airs of the opposite gender not because this was his or her natural disposition but because he or she wanted to, was very different. This person is engaged in imitating (tashabbuh) the opposite sex, an act that the Prophet ﷺ severely criticized in sound hadiths (though he also explicitly said that such a person should not be killed).
Here it’s important to note that ‘imitating’ the opposite sex has always been understood as contextual by Muslim scholars. How a man or woman dresses or acts depends on their local culture. What is masculine in one culture might be feminine in another. So whether a person is affecting the mannerisms or dress of the opposite sex can only be known in the context of the specific customs (ʿāda) of their society. As Ibn Ḥajar notes, “How many people there are among whom the dress of their women does not differ at all from the dress of their men?”
In another important sense, however, the shariah position falls far from the ‘progressive’ mark. The Qur’anic and Prophetic exemption for men who have no desire for women is not some recognition of a third gender or a validation of same-sex acts. These effeminate men, or men who are not attracted to women, are still men in the eyes of the shariah in every other aspect (mutatis mutandis true for women).
On the issue of surgery to change someone’s gender, Muslim scholars have a surprising diversity of views. By far, the dominant opinion among Sunni scholars is that it’s impermissible. In 1989, the Muslim World League’s Fiqh Academy declared sex-change surgery prohibited except in the case of the khunthā mushkil, namely an adult person who has no distinguishing gender markings of any sort (rare indeed). In such a case, the person’s subjective gender identity is literally the only thing to go on. But this ruling did not acknowledge the reality of someone believing subjectively that their gender was different from their biological sex if that biological sex was clear.
A few Muslim scholars have disagreed. In 1967, the Ayatollah Khomeini (d. 1989) and the former Grand Mufti of Egypt, Jād al-Ḥaqq (d. 1996), seem to have endorsed sex-change surgery under certain conditions, namely situations in which psychiatric experts had concluded that a person’s gender really did not accord with their biological sex. A subsequent Grand Mufti of Egypt, Sayyid Ṭanṭāwī (d. 2010), issued a fatwa in 1988 that allowed the surgery if doctors testified that it was the only cure for a person’s gender dysphoria, which the fatwa viewed as a psychological disorder. But none of these fatwas really engaged the question of whether diagnosing gender dysphoria (or “psychological hermaphroditism”) as a disorder was acceptable in Islamic law. Shia scholars have been more open to the idea due to a conception of identity that lends more weight to subjective psychological opinion, though many Shia scholars remain highly skeptical (stating that gender reassignment surgery only involves a superficial change to the body and does not alter the person’s actual gender).
From LGBTQ and Islam Revisited: The Days of the Donald by Dr Jonathan Brown