While sounds bad, I see logic here. For serial child rapists, many cannot control their urge and this is only way to protect children other than life in prison or death penalty. And if rape has same penalty as murder, just incentivizes rapists to kill their victim. I get it sounds backwards but see logic and also it can be done chemically, doesn't have to involve physical surgery.
The thing is even with chemical or physical castration, one can still get hard and utilize their penis with intercourse. The removal of the penis of man is in itself a needlessly cruel mechanism of legal action with negative health consequences and astounding mental anguish for a man, and while chemical castration is in itself less invasive it has complications and negative ramifications of this nature.
These sort of heavy measures, in and of themselves without seeking a therapist or getting isolated from the general population through normal procedures, should ideally be only used as a method of last resort.