There's some inconsistency throughout Islam, with two diametrically opposite arguments.
Transgender people are mistaken or confused
In this interpretation, transgender people are victims, perhaps confused by Shaytaan's whisperings. A person's true, innate, God-given gender is determinable from some measurable, unchangable aspects of their biology at birth.
It is not permissible for a person to change sex from male to female or vice versa. The Muslim has to be content with what Allaah has decreed, for He has placed him in a suitable position.
...
Changing one’s sex is a kind of tampering with the creation of Allaah and following the way of the Shaytaan who vowed that he would misguide the sons of Adam in this way and in others, as Allaah tells us that he said:
"and indeed I will order them to change the nature created by Allaah" -- Qu'ran 4:119 -- Sheikh Muhammed Salih Al-Munajjid , 2001 (Fatwa 21277)
and
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.
This operation is haraam in Islam, according to all the reputable contemporary scholars. -- Fatwa 34553, 2004
However, this fatwa also says
The surgery that is permissible in such cases is if a person was originally created male or female, but his genital organs are hidden.
which indicates some possibility of exceptional cases.
It is not permissible for either a man whose male organs are fully formed or a woman whose female organs are fully formed to change into the other gender. The attempt to do so is a crime, the perpetrator of which deserves to be punished for changing the creation of Allah. -- Islamic Fiqh Council of the Muslim World League, Decision No. 5, Session 11, 1989 (link)
The above fatwa was cited in the following fatwa:
We know, therefore, that these operations are prohibited and that no one from among the scholars whose opinion is considered permits them, save with the exception mentioned in the council's response. -- Dr. Hatem al-Haj, Assembly of Muslim Jurists of America (AMJA) (Fatwa 22813, 2007)
The transition of this category is a great crime: it is mutilation, changing the creation of Allah and imitation of the opposite sex—and those who do these things have been cursed by the Prophet (saws). ... having sex reassignment therapy is a prohibited act according to Shari`ah ... -- AMJA Fatwa Committee, 2008 (Fatwa 21701)
Kuwait has a law which has been used against cross-dressers (Cross-dressers' heads shaved in Kuwait). It's unclear if this applies to transsexuals with updated documents (they might consider them "cross-dressers" in this context).
Article 198 prohibits "imitating the appearance of a member of the opposite sex" with fines and or imprisonment. (2007) -- Wikipedia
Malaysia is known to convicted transgender people under Sharia law (e.g. 12 Transgender Women Arrested in Penang, Malaysia Under Violation of Anti-Crossdressing Law):
Any male person who, in any public place, wears a woman's attire and poses as a woman for immoral purposes shall be guilty of an offence and shall on conviction be liable to a fine not exceeding one thousand ringgit or to imprisonment for a term not exceeding one year or to both. -- Section 28
Transgender people should realize their innate gender
Transgender people have a God-given innate gender that does not (or did not originally) match their worldy, external appearance. Transgender people may transition to more closely resemble their God-given gender. Indeed, this is the official position in Iran:
Q1271. Some people have the appearance of men. They have female psychological and sexual tendencies though. If they do not undergo the operation of sex change, they might commit sins insofar as their sexual behavior is concerned. Is it permissible for them to undergo such an operation?
A: There is no harm in undergoing the said operation if the end result would be determining of the true sex of the person provided that it does not lead to the commission of any ḥarām act or a vile consequence. -- Iran's Ayatollah Khamenei's website
The origin seems to be a fatwa by Ayatollah Khomeini:
Khomeini, however, did give [Maryam Khatoon Molkara] a letter to authorize her sex reassignment operation, which she later did in 1997. Due to this fatwa, issued in 1987, transsexual women in Iran have been able to live as women until they can afford surgery, have surgical reassignment, have their birth certificates and all official documents issued to them in their new gender, and get married to men. -- Wikipedia
Unlike homosexuality, transgender people need referrals from medical professionals to get treatment (who don't regard the treatment as wholly cosmetic). Islam generally interprets surgery for medical reasons as an exception to "tampering with Allah's creation" (as well as for some cosmetic reasons, such as congenital faults).
Since, in Islam, men should act like men, and women should act like women, with this innateness interpretation, it could be regarded as haram not to transition to your "true sex", i.e., continuing to imitate one gender while knowing in your heart that God made you another gender.
'Surely, Allah curse the women who imitate men and men who imitate women.' -- Bukhari
While Islam Q&A's attitude is primarily to regard transitioning as haram (as above), the following fatwa, while also mostly discouraging transitioning, claims it can be halal:
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. -- Shaykh ‘Abd al-‘Azeez ibn Baaz, Shaykh ‘Abd ar-Razzaaq ‘Afeefi, Shaykh ‘Abdullah ibn Qa‘ood, Shaykh ‘Abdullah ibn Ghadyaan, 2014 (Fatwa 138451)
The following opinion differs from the mainstream in that it rejects the idea that a transgender person's body is "wrong" both before and after surgery:
You were not in the wrong body then and you are not in the wrong body now. According to Shari'a now you are a woman so do your best to be a good person and build up your eternal spiritual life without too much emphasis on the mortal body. -- Hajj Gibril Haddad, 2012 (eShaykh.com Gender Change Question)
If physical characteristics and self-identity (how a person identifies themselves) are mostly feminine then the person is a woman. -- Hajj Gibril Haddad, 2012 (eShaykh.com About Hard Situation: Transexual)
This opinion even argues against the "tampering with Allah's creation" argument:
Consequently, there will be no difference between the transsexual and any female except in casual attributes as when a woman has no uterus or she can’t carry a baby since ordinary women may undergo such condition.
...
It is worth mentioning that I am not the only one who adopts such a ruling, for both Imam Khoui in his book “Mounyat El Sail” (the wish of the one who asks) approved sex-change.
...
And if we adhere to the impermissibility of altering Allah’s creation, as understood and construed by those religious scholars, then we will have to protect trees, plants, lands, mountains and rivers from change even though no one will comply to it, which is disapproved by rational people, knowing that, most jurists adhere to the permissibility of changing one’s sex, in addition to man’s beautification changes. -- Jurisprudence of sex, Sayyed Muhammad Hussein Fadlullah
Recent news from Pakistan (July 2016) Pakistani Clerics Issue Fatwa Approving Transgender Marriage reports:
Fifty Pakistani clerics based in Lahore have issued a fatwa, or religious decree...
"We need to accept them as God’s creation too. Whoever treats them badly, society, the government, their own parents, are sinners," Naqshbandi said, according to the Wall Street Journal.
"It is permissible for a transgender person with male indications on his body to marry a transgender person with female indications on her body," the fatwa stated. "Also, normal men and women can also marry such transgender people as have clear indications on their body."
(Implicit in this latter part is the acceptance of transgender women as women and transgender men as men. They certainly wouldn't be saying it's okay for transgender women to marry men if they interpreted them as men.)
That being so, the rulings derived from these and other noble hadiths on treatment grant permission to perform an operation changing a man into a woman, or vice versa, as long as a reliable doctor concludes that there are innate causes in the body itself, indicating a buried [matmura] female nature, or a covered [maghmura] male nature, because the operation will disclose these buried or covered organs, thereby curing a corporal disease which cannot be removed, except by this operation.
Indeed, it is obligatory to do so on the grounds that it must be considered a treatment, when a trustworthy doctor advises it. It is, however, not permissible to do it at the mere wish to change sex from woman to man, or vice versa. -- Egypt's former grand Mufti Al-Azhar Sheikh Mohamed Tantawi (1988)
He cites the hadith "God never gave a disease without providing a cure or a medicine for it, except for one disease." Jakob Skovgaard-Petersen comments:
This is a rather difficult fatwa, and so vague that both parties cited it in support of their position, as we have seen. ... Mufti Tantawi seems to be squarely on the side of medicine in this matter.
Sheikh Tantawi's fatwa was cited in a Kuwait legal case: Kuwait sex-change case upheld.
A historical case of transgender people in Islam include Mukhannathun ("effeminates"):
A mukhannath is the one ("male") who carries in his movements, in his appearance and in his language the characteristics of a woman. There are two types; the first is the one in whom these characteristics are innate, he did not put them on by himself, and therein is no guilt, no blame and no shame, as long as he does not perform any (illicit) act or exploit it for money (prostitution etc.). The second type acts like a woman out of immoral purposes and he is the sinner and blameworthy. -- al-Nawawi
...while the Prophet was with her, there was an effeminate man in the house. The effeminate man said to Um Salama's brother, `Abdullah bin Abi Umaiyya, "If Allah should make you conquer Ta'if tomorrow, I recommend that you take the daughter of Ghailan (in marriage) for (she is so fat) that she shows four folds of flesh when facing you and eight when she turns her back." Thereupon the Prophet said (to us), "This (effeminate man) should not enter upon you (anymore). -- Um Salama
There's also the Xanith in Oman.
Xanith (sometimes also transcribed from the Arabic as khanith or khaneeth) is the name for effeminate men who act the passive part in homosexual relationships in the northeastern coastal region of Oman. They are socially classified with women with respect to the strict rules of segregation and speak of themselves as "women." Many are prostitutes. The character of xanith is most clearly shown in counterpoint to male and female roles. -- "Xanith (Oman)", U. Wikan, The International Encyclopedia of Human Sexuality
I'm not entirely familiar with the Shia/Sunni divide on this matter, but Ayatollah Khomeini's fatwa was clearly a major influence for Shia Islam. Judging from the above, Sunni Islam doesn't seem all that bad, although clearly not as favourable as Shia Islam.