Nasir Ahmad El-Rufai, the governor of Kaduna state, where the legislation has been introduced, said the "drastic penalties are required to help further protect children from a serious crime".
While some Nigerians are pleased that drastic action is being taken, critics say the new law is too harsh and may even lead to fewer rapes being reported.
The new law follows a spike in reports of rape in Nigeria over the course of the coronavirus pandemic, leading women’s groups to call for harsher penalties against sex offenders.
The country’s minister for women’s affairs said in June that the number of rapes had tripled due to women and girls being in lockdown with their abusers.
In the same month, all 36 state governors declared a state of emergency of violence against women and girls.
The country has a long-standing problem of sexual violence. One in four girls is sexually abused before they turn 18, according to Unicef.
The change to the penal code may backfire, one Nigerian lawyer and activist, Chidi Odinkalu, told the New York Times.
As many rapes happen within marriage – in Nigeria and elsewhere – women and girls may be less likely to report a crime that their husband could be castrated for, in fear of being ostracised by their families and communities.
“You’re going to get fewer cases of rape and sexual violence reported,” he said. “What’s wrong with life imprisonment?”
The human rights activist described the new law as “legislative sadism”.