First of all, let me make a small disclaimer: The words intersex and transgender describe two completely different things. Also, they are two modern and Anglo-European words to describe certain characteristics of people that always have been around, yet in other times, places, and cultures people have found different concepts to describe and categorize these characteristics, e.g. descriptions like two spirit, hijra, fafafine, a.s.o.

Now, based on this, it is pretty difficult to say this and that term in 7th century Arabic meant for sure intersex or transgender, yet there are good indicators that it both roughly is connected to words based on the consonants kh-n-th (in Arabic the meaning of words is based on the 3 root consonants every word has). While khuntha is closer connected to intersex, mukhannath would rather be connected with transgender.

The Oldest Islamic Source: The Qur’an

I have to start with the disappointing message that actually if you search the root kh-n-th in the Qur’an, you will not find anything. There is no word connected to this root.

The Second Source: Narrations (Hadith)

In Islamic Traditions scholars collected narrations about the times of the Prophet (ﷺ) and himself. Actually, people started collecting pretty early, around 200 years after the death of the Prophet (ﷺ). Also, they wrote down the people who told them the narration in a chain that leads back to the first person narrating this story. Back then already, they tried to figure out which narrations are likely to be true, and which are not.

The sunni scholars agreed on 6 books they view as the canonic and most scientific books that collected narrations. (Other muslim tradition have other canonic books, I just picked the largest tradition too keep it short.) If you now search the root kh-n-th in these books, you will not find khuntha (~intersex), but you will find different variations of two narrations containing the word mukhannath (~transgender).

Hadith: The Mukhannath And The Wives of The Prophet (ﷺ)

Narrated Aisha, Ummul Mu’minin: A mukhannath (eunuch) used to enter upon the wives of Prophet (ﷺ). They (the people) counted him among those who were free of physical needs. One day the Prophet (ﷺ) entered upon us when he was with one of his wives, and was describing the qualities of a woman, saying: When she comes forward, she comes forward with four (folds in her stomach), and when she goes backward, she goes backward with eight (folds in her stomach). The Prophet (ﷺ) said: Do I not see that this (man) knows what here lies. Then they (the wives) observed veil from him.
Grade: Sahih (Al-Albani);  Reference: Sunan Abi Dawud 4107

translation by sunnah.com, original by Abu Dawud, hadith no. 4107
The two things I marked as wrong in the translation are interpretations of the translator, the original text does not contain the words assumed by the translator.
Also, the hadith uses male pronouns for the mukhannath, but also genderless/ gender neutral beings like angels are refered to with he-pronouns in Arabic.

So, what I understand here is that a mukhannath (~transgender woman) worked for the wives of the Prophet (ﷺ) or at least was friends with them, and therefore often talked to them. In other variations of this narration we also learn that Umm Salama (a wife of the Prophet (ﷺ), r.a.a.) talked to the mukhannath about her brother. The mukhannath then gave her advice which woman her brother should marry. Exactly in this moment the Prophet (ﷺ) came in and then doubted that the mukhannath doesn’t experience sexual attraction to woman. In consequence the wives of the Prophet ((ﷺ), r.a.a.) started to veil in front of this mukhannath.
[You can find different versions of this narration in Buḫārī (4324, 5235, 5887), Muslim (2181), and Abū Dāwud (4107 & 4929)]

So, what we can see here is that first, the transgender woman was treated in a female gender role (>The women didn’t veil in front of her.) Afterwards they did veil, but not in general in front of every transgender woman but just in front of her. So, I would say, this could indicate that people can decide to veil based on (actual – not assumed) sexual orientation instead of gender.
Also, we can see that being transgender can not be something forbidden, because otherwise the Prophet (ﷺ) would have been obligued to say something in this situation. Furthermore, it is permitted to be friends with transgender people, as the wives of the Prophet (ﷺ) (namely Aisha (r.a.a.) and Umm Salama (r.a.a.)) were.

Hadith: Don’t Call Men Transgender

That the Prophet (ﷺ) said: „If a man says to another man: ‚O you Jew‘ then beat him twenty times. If he says: ‚O you effeminate‚ then beat him twenty times. And whoever has relations with someone that is a Mahram then kill him.“
Grade: Da’if (Darussalam); Reference: Jami` at-Tirmidhi 1462

translation by sunnah.com, original by Tirmidhi, hadith no. 1462
The original says „mukhannath“ instead of „effeminate“.
You can find a different version of this hadith in Abu Dawud’s Sunan Book, hadith no. 2568

Compared to the narration above which you can find in three canonic hadith books, and which is classified most likely to be true (sahih), this hadith here is only found in two canonic book and classified as unlikely to be true (daif). Yet, if it’s true it tells us that people shall not use transgender as a swear word.
If you allow more conclusion, you might also interpretate this as „Don’t call a man a transgender woman, when he’s not“, so we could conclude the analogy „Don’t call a woman a transgender man.“ and in general „Don’t call people something they are not“.
Furthermore, if you allow conclusions by analogy and abstraction from historic to modern times, you could come to the conclusion, that for nowadays this would mean, that it is not permissable to misgender people.

You can choose, how far you would go with this interpretation and beforehand, with believing in this narration.

Conclusions

First of all, if being intersex or being trangender itself was problematic or prohibitted, either the Qur’an or the Hadith or the Prophet (ﷺ) himself in the narration would say that. Since, they don’t, it could only be prohibitted by (a strong and logic) analogy. So, one would need to find something comparable to being intersex or transgender and this something needs to be directly prohibitted in Qur’an or Hadith – and I honestly don’t know what could be comparable. So, for Islamic law that means: perfectly fine. (Also, there are jurisprudence texts from later centuries that give the advise to let children who are khunta (~intersex) grow up and then decide in which gender role they would like to live in, a.s.o.)

Outside of Islamic law, that also means, that people can be muslim and transgender (as the mukhannath in the hadith was), be friends with transgender people (as Aisha (r.a.a.) and Umm Salama (r.a.a.) were), and that transgender shall not be viewed as a swearword (same goes for jew in the hadith).

Note: For more and better knowledge about intersexuality, please visit Zwischengeschlecht.org
Also, disclaimer: I tried to keep it simple, and explain the necessary parts of three main islamic sciences for readers who never heard a single word of this. If you need deeper scientific resources regarding this topic, please feel free to ask for them in the comments, and I can provide you with links, books, and articles.
And: If you know a different source that provides additional knowledge or contradicts something in this article, please leave a comment down below, I’m very open and happy to look into these sources.