I know that in the Ottoman Caliphet, the janissaries were castrated, so was castration permitted according to Sharia Law
Castration is totally prohibited in Islam, either for slaves or free men .
Stated in the hadith :
عن عبد الله بن مسعود قال : كنا نغزو مع رسول الله صلى الله عليه وسلم ، وليس لنا شيء ، فقلنا : ألا نستخصي ؟ فنهانا عن ذلك . رواه البخاري ( 4787 ) ومسلم (1404)
Narrated Ibn Masud: We used to fight in the holy battles in the company of the Prophet (ﷺ) and we had nothing (wives) with us. So we said, "O Allah's Messenger (ﷺ)! Shall we get castrated?" The Prophet (ﷺ) forbade us to do so.