Praise be to Allah.
It is not possible for anyone, no matter who he is, to change the creation of Allah, may He be exalted, from male to female or vice versa. Whoever Allah, may He be exalted, has created as a male can never become a female who menstruates and gives birth!
Yes, the doctors may tamper with him to satisfy his perversion so that he will think that he has become a woman, but he will never be truly female and will live in a state of anxiety and worry, which may lead him to commit suicide.
What a person may feel in his mind and heart, that he is of a gender other than what he appears to be to us does not give him an excuse to change his gender; rather it comes under the heading of following the Shaytaan in changing the creation of Allah – outwardly but not truly – and those feelings do not make it permissible for him to undergo surgery or take medicines and hormones to change his outward appearance. Rather he must be content with the decree of Allah, may He be exalted, and treat his case on the basis of faith and obedience to Allah. It is not permissible for him to make himself appear outwardly to be of a gender other than his real gender with which Allah created him, otherwise he will be committing a major sin; if this person is really female then she will be masculinised and if he is really male then he will be effeminate.
Please see also the answers to questions no. 21277 and 34553
The surgery that is permissible in such cases is if a person was originally created male or female, but his genital organs are hidden. In that case it is permissible to do surgery in order to make those organs appear, and to give him or her medicine or hormones to strengthen the characteristics with which Allah originally created him or her.
But in the case of one who was created with both female and male genitalia – this is what is called ambiguous intersex – it is not permissible to be hasty in removing one and making the other more apparent. Rather we should wait until it is known what Allah, may He be exalted, will decree for this individual, which may become apparent after some time has passed.
For a more detailed discussion on intersex please see the answer to question no. 114670
There follows a detailed fatwa from the scholars of the Standing Committee for Issuing Fatwas, who were asked about a case similar to what is mentioned in the question. They replied:
Firstly: Allah, may He be exalted, says (interpretation of the meaning): “To Allah belongs the kingdom of the heavens and the earth. He creates what He wills. He bestows female (offspring) upon whom He wills, and bestows male (offspring) upon whom He wills. Or He bestows both males and females, and He renders barren whom He wills. Verily, He is the All-Knower and is Able to do all things” [ash-Shoora 42:49]. So the Muslim must accept and be content with whatever Allah creates and decrees.
In your case, if you are as you mentioned, that you are certain of your masculinity and that you can play the male role efficiently, even if you have not actually engaged in any sexual activity with any person, then you must preserve your masculinity and accept that which Allah has granted to you of virtue and a favourable situation. .
Secondly: once your masculinity is proven and established, then having surgery to turn into a female – as you think – is changing the creation of Allah, and is an expression of discontent on your part with what Allah has chosen for you, even if we assume that the surgery is going to be successful and lead to what you want of becoming female. But there is no way that it can be successful, for both males and females have their own, distinct faculties and physical makeup, the development and characteristics of which are decreed only by Allah, may He be exalted, and are not just the penis of the male or the vaginal opening of the female. Rather the man has a complete, integrated system comprising the testicles and other organs, each of which has a special function and characteristics, and produces specific secretions and so on. Likewise the woman has a uterus and other connected parts that work in harmony with it, and each part has its own function and characteristics, and produces specific secretions and so on. Among all of them there are connections and harmony over which none of His creation have any power of estimation, creation, control, management or preservation. Rather all of that is under the control of Allah, the All-Knowing, Most Wise, Most High, Almighty, Most Kind and All-Aware.
Therefore the surgery that you want to do is a kind of tampering and striving for something in which there is no benefit. In fact it may be dangerous; if it does not lead to death, then at the very least it will lead to taking away that which Allah has given you without you attaining what you want, and you will still be affected by what you have mentioned of psychological problems that you want to get rid of by means of this surgery that is bound to fail.
Thirdly: if your masculinity is not established, and you only think that you are a man because of what you see in your body of outward masculine appearance, in contrast to what you feel in yourself of having feminine characteristics and an inclination towards males and being sexually attracted to them, then you should examine your situation and not go ahead with the surgery that you have mentioned. You should consult experienced specialist doctors. If they determine that you are male in outward appearance but are in fact female, then you may submit yourself to their treatment, so that they can bring out your femininity by doing surgery. But that will not in fact be a sex change from male to female, because this will not be up to them; rather it will be bringing out your true nature and removing what is in your body, and what you feel deep inside you of confusion and ambiguity. But if nothing is clear to the experts, then do not take the risk of undergoing this surgery; be content with the decree of Allah and be patient with what has befallen you, seeking to please your Lord and protecting yourself against the possible consequences of doing an operation without guidance and insight concerning your condition. Turn to Allah and beseech Him to relieve you of what you are facing, and to heal you from your psychological problems, for control of all things is in His hand, may He be glorified, and He is able to do all things. End quote.
Shaykh ‘Abd al-‘Azeez ibn Baaz, Shaykh ‘Abd ar-Razzaaq ‘Afeefi, Shaykh ‘Abdullah ibn Qa‘ood, Shaykh ‘Abdullah ibn Ghadyaan
Fataawa al-Lajnah ad-Daa’imah (25/45-49)
And Allah knows best.