These people who hate the sex with which they were created and wish that they were of the other sex, are in fact mentally ill. It may be caused by a bad upbringing in some cases, and by the nature of the society in which they live in other cases, which makes them hate the way they are. So they object to the decree of Allaah and they want to change their sex from one to the other.
There may be some (acceptable) reasons for having a sex-change operation that turns one from a male into a female. But what is mentioned in the question is no more than a wish or a desire, although the male genitalia were complete. It is not a case of what the fuqaha’ call al-khuntha (hermaphrodite). Rather this person is naturally male, with all the attributes of masculinity, but he wants to turn into a female, so he has surgery to remove the penis and testicles, then the doctors construct a vagina and increase the size of the breasts, and administer hormone injections over a lengthy period until the voice becomes softer and the distribution of fat on the body changes, and the person appears outwardly to be female, but in fact he is a male.
This operation is haraam in Islam, according to all the reputable contemporary scholars. The earlier scholars did not discuss it because it was not known and was not possible during their time. The fact that it is forbidden is indicated by a number of things, including the following:
Firstly: the verses in which Allaah says (interpretation of the meaning):
‘They (all those who worship others than Allaah) invoke nothing but female deities besides Him (Allaah), and they invoke nothing but Shaytaan (Satan), a persistent rebel!
118. Allaah cursed him. And he [Shaytaan (Satan)] said: “I will take an appointed portion of your slaves.
119. “Verily, I will mislead them, and surely, I will arouse in them false desires; and certainly, I will order them to slit the ears of cattle, and indeed I will order them to change the nature created by Allaah.” And whoever takes Shaytaan (Satan) as a Wali (protector or helper) instead of Allaah, has surely, suffered a manifest loss.
120. He [Shaytaan (Satan)] makes promises to them, and arouses in them false desires; and Shaytaan’s (Satan) promises are nothing but deceptions.
121. The dwelling of such (people) is Hell, and they will find no way of escape from it’
Undoubtedly doing such operations is a kind of toying with and changing the creation of Allaah.
Secondly: It is proven in al-Saheeh that ‘Abd-Allaah ibn ‘Abbaas (may Allaah be pleased with him) said: The Messenger of Allaah (peace and blessings of Allaah be upon him) cursed men who imitate women and women who imitate men. Narrated by al-Bukhaari, 5546.
Ibn Hajar said: For men to imitate women and women to imitate men, deliberately and by choice, is haraam according to scholarly consensus.
Thirdly: the Prophet (peace and blessings of Allaah be upon him) forbade hermaphrodites to enter upon women, if they pay attention to women and their charms, and he ordered that they be banned from living among people so as to guard against their evil.
Imam al-Bukhaari included this hadeeth in two chapters: (1) under the heading: “It is forbidden for men who resemble women to enter upon women” and (2) under the heading: “Expelling men who resemble women from people’s houses.”
Ibn Hajar said: What we learn from this is that women should observe hijab before those hermaphrodites who pay attention to women's charms, and that they should be banned from living among people, as a means to deter them. And it seems that doing this is obligatory.
Fourthly: According to specialist doctors, this kind of operation is not indicated by any kind of sound medical evidence, and it is no more than the matter of personal whims and desires.
And there is other evidence which indicates that it is haraam. For more information, please see the book Ahkaam al-Jaraahah al-Tibbiyyah, p. 199
Dr Muhammad ‘Ali al-Barr said: Although the outward appearance of such a person may deceive you into thinking that he is female, in fact his biological structure remains male, even if it has been obliterated completely. Moreover, there is no ovary or uterus and such a person cannot menstruate or get pregnant at all.
Based on the above, it is not permissible under any circumstances for a woman to be alone with him, or to uncover or take off her hijab in front of him, because he is in fact male, even though he may now feel attracted towards males, because of the many female hormones in his system. Undoubtedly these people are worse than the hermaphrodites whom the Prophet (peace and blessings of Allaah be upon him) forbade to enter upon men, and ordered that they be banned from living among the people.
Hence it may be more appropriate for more than one person to meet with him, and to take him to a trustworthy psychologist who can treat his illness. We ask Allaah to guide him and set his affairs straight.
You could speak to a trustworthy Shaykh or seeker of knowledge, and ask him to receive this person and teach him about his religion and its rulings, and strengthen his ties with Islam and help him to grow steadfast in his faith. This should be done in the presence of more than one person. You should also understand that after doing as much as you can for this person, guidance is in the hand of Allaah; He guides whomsoever He will of His slaves. And Allaah knows best.