All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
People are either male or female, and there is no third kind in reality because Allah the Almighty says (what means): {And that He creates the two mates – the male and female – from a sperm drop when it is emitted.} [Quran 53: 45, 46]. However, some people may be born, and it is not known whether he is male or female because he has male and female genitals as if he has a man’s penis and a woman’s vagina, and this is what is known to jurists as a hermaphrodite. In fact, he is either a male or a female, but it is confusing for us to determine. Ibn Qudamah said in (Al-Mughni):
"The hermaphrodite is the one who has two genitals. A man’s penis, and a woman’s vagina. And he shall be either male or female. Allah The Exalted says (what means): {And that He creates the two mates – the male and female} [Quran 53:45]. And He, The Exalted, says (what means): {and dispersed from both of them many men and women.} [Quran 4:1] Then there is no third creation. Besides, the hermaphrodite is either ambiguous or unambiguous. If the hermaphrodite is unambiguous, such as having masculine signs, then the rulings for men apply on him. However, if he has female signs, then the rulings for women apply on him.
If there is no way to distinguish his masculinity from his femininity – then this is an ambiguous hermaphrodite, and the jurists have mentioned many rulings regarding him, such as the rulings related to his inheritance, does he inherit the share of a male or the share of a female?, and in terms of his marriage and that he is not to be married off before his gender is determined. They also mentioned controls through which he can be determined whether he is male or female. In modern medicine, there are operations conducted on him that determine the prevailing characteristics. On that basis, the operation shall be conducted, so he shall not remain hermaphrodite, either a man characterized by full features of masculinity or a female with complete characteristics of femininity.
The Jurists stated that the hermaphrodite should be treated according to the precautionary principle until his gender is determined. So men treat him as a woman, and women treat him as a man. The Encyclopedia of Fiqh (Islamic jurisprudence) reads: The rulings of hermaphrodite: the general criterion in setting the rulings of the hermaphrodite is that to be treated in religious affairs according to the precautionary principle, and any doubtful ruling shall not be confirmed.
In the same encyclopedia, it was stated: "The majority of jurists stated that the hermaphrodite shall not be met in privacy (without Mahram) whether by a man or woman, and he shall not travel without a mahram (from men) as a precaution measure to avoid the probability of falling into sin. Besides, the teenager hermaphrodite shall not be uncovered in front of women because he might be a man, and shall not be uncovered in front of men because he might be a woman.
Allah knows best.