Rapists always pose an immediate grave threat to their victims. It's part and parcel of being raped.
They also always are an immediate and grave threat to the community as they can, will and do rape dozens of people in their lifetime. IIRC the average is about 100 over their lifespan.
So yes, we can morally do so. The law is archaic, outdated, sexist, anti-victim and therefore needs to be ignored or repealed so social and moral progress can continue.