The ruling on castration
Question

                What is the ruling on eunuchs? What are the laws that apply to them? Should they pray with the men or with the women?
Praise be to Allah.Firstly: 
Castration is removal of the testicles. The Arabic word translated here as castration may also refer to removal of the testicles and penis. 
Some scholars differentiated between the two and said: If his testicles only are cut off, then he is a eunuch; if his penis is cut off, then he is emasculated. 
It is haraam for a person to do that deliberately to himself or to someone else. 
In al-Mawsoo‘ah al-Fiqhiyyah (19/120, 121) it says: 
Castration of the human is haraam, whether he is a child or an adult, because of the prohibition on that, which we will see below: 
Ibn Hajar said: it is prohibited, therefore it is haraam, and there is no difference of opinion concerning that in the case of the sons of Adam (i.e., humans). 
Among the reports that confirm this prohibition is the following: 
‘Abdullah ibn Mas‘ood said: We were on a campaign with the Messenger of Allah (blessings and peace of Allah be upon him), and we had no women with us. We said: Why don’t we get ourselves castrated? But he forbade us to do that.
Narrated by al-Bukhaari (4787) and Muslim (1404). 
According to the hadeeth of Sa‘d ibn Abi Waqqaas: The Messenger of Allah (blessings and peace of Allah be upon him) forbade ‘Uthmaan ibn Maz’oon to be celibate. If he had given him permission, we would have gotten ourselves castrated.  
Narrated by al-Bukhaari (4786) and Muslim (1402). 
Ibn Hajar said, commenting on these hadeeths: 
The wisdom behind the prohibition on castration is that it is contrary to what the Lawgiver wants of increasing reproduction to ensure continuation of jihad against the disbelievers. Otherwise, if permission had been given for that, then many people would have done that, and reproduction would have ceased, and the numbers of Muslims would have become less as a result, and the numbers of disbelievers would have increased, and that is contrary to the purpose for which the Prophet (blessings and peace of Allah be upon him) was sent. 
It also has a number of negative consequences: self-injury, deformity and causing harm that may lead to death. It also eliminates the quality of masculinity that Allah created in the man, and it is changing the creation of Allah, and is a kind of ingratitude for blessings. Moreover it is an imitation of women and choosing that which is imperfect over that which is perfect.
End quote. Fath al-Baari (9/119). 
Secondly: 
The eunuch who has lost all desire for women comes under the same heading as  “old male servants who lack vigour”, who are the ones for whom it is permissible to see a woman’s adornment as her mahrams are allowed to see it. 
Allah, may He be exalted, says (interpretation of the meaning):
“And tell the believing women to lower their gaze (from looking at forbidden things), and protect their private parts (from illegal sexual acts, etc.) and not to show off their adornment except only that which is apparent (like palms of hands or one eye or both eyes for necessity to see the way, or outer dress like veil, gloves, head-cover, apron, etc.), and to draw their veils all over Juyubihinna (i.e. their bodies, faces, necks and bosoms, etc.) and not to reveal their adornment except to their husbands, their fathers, their husbands fathers, their sons, their husbands sons, their brothers or their brothers sons, or their sisters sons, or their (Muslim) women (i.e. their sisters in Islam), or the (female) slaves whom their right hands possess, or old male servants who lack vigour, or small children who have no sense of the shame of sex. And let them not stamp their feet so as to reveal what they hide of their adornment. And all of you beg Allah to forgive you all, O believers, that you may be successful.”
[an-Noor 24:31]. 
Ibn al-‘Arabi al-Maaliki (may Allah have mercy on him) said: 
Ashhab said: Maalik was asked: Can a woman take off her head cover in front of a eunuch? Is he one of those who “lack vigour”? He said: Yes, if he is her slave or the slave of someone else. But in the case of one who is free, then no. 
Ahkaam al-Qur’an (6/73). 
The Hanafis differed concerning that – according to one of their views – but the most correct view is that of the majority. 
In al-Mawsoo‘ah al-Fiqhiyyah (3/8) it says: 
The more correct view according to the Hanafis is that with regard to looking at a non-mahram woman, the eunuch, the emasculated man, the old man, the slave, the effeminate man, the feeble-minded man, and the simpleton are like the one who possesses vigour, because a eunuch may have intercourse and his child may be attributed to him, and the emasculated man may feel pleasure and ejaculate, and the effeminate man is an evildoer who possesses vigour. As for the feeble-minded man and the simpleton, they feel desire, and they may speak of what they see. 
The Maalikis, Shaafa‘is and Hanbalis – and one view among the Hanafis – say that the ruling on men who “lack vigour” is the same as the ruling on mahrams with regard to looking at women: they may see of them the places where adornment is worn, such as the hair and forearms; they also come under the same ruling as mahrams with regard to entering upon them, because Allah, may He be exalted, says (interpretation of the meaning): “… or old male servants who lack vigour...” [an-Noor 24:31].
End quote. 
The scholars of the Standing Committee were asked: What is meant by  “… or old male servants who lack vigour...” [an-Noor 24:31]? 
They replied: 
What is meant by those who lack vigour is those who serve the people of a household by bringing food and the like and have no need of women because they are impotent or feebleminded, so they pay no attention to that which may provoke desire of adornment  and beauty, or old men whom age has weakened to the point that they pay no attention to women, and others who have lost all desire for women for various reasons, so they are safe to be with, and there is no fear of temptation from them. So women may show before them whatever adornment it is permissible for them to show in front of their mahrams as mentioned in the verse, and those who come under the same rulings, such as women and young children who have not reached the age of discernment whereby they can understand what a woman’s ‘awrah is and be provoked by it. 
Shaykh ‘Abd al-‘Azeez ibn baaz, Shaykh ‘Abd ar-Razzaaq ‘Afeefi, Shaykh ‘Abdullah ibn Ghadyaan, Shaykh ‘Abdullah ibn Qa‘ood. 
Fataawa al-Lajnah ad-Daa’imah (4/264, 265)
 In the case of one who is thought not to be one of those men who lack vigour, and appears to be otherwise, he is to be regarded like other men who possess vigour, and he is not to be allowed to see the adornment of non-mahram women. 
It was narrated that ‘Aa’ishah said: An effeminate man used to enter upon the wives of the Prophet (blessings and peace of Allah be upon him), and they regarded him as one of those who are without desire. The Prophet (blessings and peace of Allah be upon him) came in one day when he was with one of his wives, and he was describing a woman. He said: She shows four folds when facing you and eight when she turns her back. The Prophet (blessings and peace of Allah be upon him) said: “I see that he knows about these things. He should not enter upon you.” She said: And they observed hijab before him.
Narrated by Muslim (2181). 
An-Nawawi (may Allah have mercy on him) said:
With regard to the effeminate man initially entering upon the Mothers of the Believers, the reason for that is explained in this hadeeth, which is that they thought that he was one of those who lack vigour and that it was permissible for him to enter upon them. But when these words were heard from him, it became known that he was one of those who possess vigour, so the Prophet (blessings and peace of Allah be upon him) forbade him to enter upon them. 
From this we learn that it is forbidden for any effeminate man to enter upon women and it is forbidden for them to appear before him, and it is clear that he comes under the same ruling as men who possess vigour and feel desire for women in this sense. The same applies to the eunuch and the emasculated man (one whose penis has been cut off).
Sharh Muslim (14/163). 
Thirdly: 
With regard to wearing ihram, praying, and other rulings, they come under the same ruling as men. So they should not enter the women’s prayer halls or pray next to the women, and they should wear what men wear in ihram. There is no difference of opinion among the scholars concerning that. 
Ibn al-Mundhir (may Allah have mercy on him) said: 
(The scholars) are unanimously agreed that the rulings on eunuchs and emasculated men, with regard to covering the ‘awrah during prayer, leading the prayer, garments to be worn when in ihram, shares of inheritance, and shares of war booty, are the same as the rulings on men. 
Al-Ijmaa‘ (p. 78). 
And Allah knows best.