Short answer
Islamic law has recognised intersex people, called khuntha, for over a thousand years. The fiqh books give rules to determine whether such a person is treated as male or female from their body's signs. Medical treatment or surgery that brings the body in line with the sex doctors find to be dominant is allowed, and is different from gender transition. Ask a mufti for an individual case.
A khuntha is assigned male or female rulings by the bodily signs: first how they urinate, then the signs of puberty. If the signs remain unclear, the person is a khuntha mushkil and the most cautious ruling applies in each matter. Treatment to clarify or correct the body according to the dominant sex is permitted.
The four schools agree on this.
Explanation
Some children are born with sex characteristics that do not fit the typical pattern, through differences of sex development (DSD) such as congenital adrenal hyperplasia or androgen insensitivity. Allah creates as He wills, and an intersex person is not to blame for their body. They have the same dignity and the same chance at Allah's pleasure as anyone else.
The classical scholars wrote whole chapters on the khuntha. In the Hanafi school, the first sign looked at is the organ used for urination. If that is unclear, puberty settles it: a beard or ejaculation points to male, breasts or menstruation to female. When the signs stay unclear, the person is called khuntha mushkil, and in each ruling, such as where they stand in prayer or how they dress for ihram, the most cautious option is taken. The other schools have similar chapters, with differences in detail.
Medical treatment. Today doctors look at chromosomes, hormones and internal organs as well. Contemporary scholars allow hormone treatment or surgery that brings the body in line with the sex that the medical evidence shows to be dominant, because it treats a condition and removes a defect. This is different from gender transition, which changes a body that is clearly one sex.
Questions families often face, such as when to operate on a baby, how to raise the child, and how marriage and inheritance apply, depend on the specific diagnosis. Work with qualified specialists, follow a qualified doctor's advice, and take the medical reports to a mufti. Above all, treat the child and adult with gentleness and privacy.
Ask a mufti about your own case. This answer explains the general ruling. When the details of your situation matter, as they do here, ask a qualified mufti and give them the full facts. Where to ask a scholar.
The evidence
Quran, Surah Ash-Shura 42:49-50
لِّلَّهِ مُلْكُ ٱلسَّمَٰوَٰتِ وَٱلْأَرْضِ ۚ يَخْلُقُ مَا يَشَآءُ ۚ يَهَبُ لِمَن يَشَآءُ إِنَٰثًۭا وَيَهَبُ لِمَن يَشَآءُ ٱلذُّكُورَ ﴿٤٩﴾ أَوْ يُزَوِّجُهُمْ ذُكْرَانًۭا وَإِنَٰثًۭا ۖ وَيَجْعَلُ مَن يَشَآءُ عَقِيمًا ۚ إِنَّهُۥ عَلِيمٌۭ قَدِيرٌۭ ﴿٥٠﴾
To Allah belongs the dominion of the heavens and the earth; He creates what he wills. He gives to whom He wills female [children], and He gives to whom He wills males. Or He makes them [both] males and females, and He renders whom He wills barren. Indeed, He is Knowing and Competent.
Allah creates as He wills, and the variety of creation is from Him.
Quran, Surah Al-Israa 17:70
۞ وَلَقَدْ كَرَّمْنَا بَنِىٓ ءَادَمَ وَحَمَلْنَٰهُمْ فِى ٱلْبَرِّ وَٱلْبَحْرِ وَرَزَقْنَٰهُم مِّنَ ٱلطَّيِّبَٰتِ وَفَضَّلْنَٰهُمْ عَلَىٰ كَثِيرٍۢ مِّمَّنْ خَلَقْنَا تَفْضِيلًۭا ﴿٧٠﴾
And We have certainly honored the children of Adam and carried them on the land and sea and provided for them of the good things and preferred them over much of what We have created, with [definite] preference.
Every person, including an intersex person, is honoured.
Sahih al-Bukhari 5678
Sahih... ما أنزل الله داء إلا أنزل له شفاء ...
"Allah has not sent down any disease without sending down a cure for it."
Medical conditions of the body may be treated.
Sahih Muslim 2564
Sahih... إن الله لا ينظر إلى صوركم وأموالكم ...
"Allah does not look at your forms or your wealth, but at your hearts and deeds."
A person's standing with Allah does not depend on their body.
Where the ruling is recorded
- al-Hidaya, Kitab al-Khuntha. Defines the khuntha and gives the signs, urination then puberty, by which rulings are assigned.
- al-Durr al-Mukhtar, Kitab al-Khuntha. The khuntha mushkil and the cautious rulings applied to them.
Checked by our team. For a more accurate answer to your own situation, consult a scholar. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.