In a first-in-the-nation ruling that is drawing both praise and denunciation, a federal judge in Massachusetts has ordered the state to pay for a convicted murderer’s sex-change operation. The state is required to pay for medical care, but the question this order raises is, How necessary is gender reassignment?

Michelle — formerly Robert — Kosilek is serving a life sentence without the possibility of parole for murdering his wife in 1990. Kosilek has been diagnosed with gender-identity disorder, an officially recognized mental illness. He has received hormone treatment and is living as a woman in a men’s prison, but has attempted to kill himself because he felt so strongly that he was living as the wrong sex.

People with gender-identity disorder like Kosilek can sometimes be treated with therapy and hormones. But according to established medical standards of care, some require gender-reassignment surgery. And the law is actually starting to turn in favor of such surgery. Last year, a court struck down a Wisconsin law prohibiting sex-reassignment surgery for prisoners. In 2010, a tax court ruled that sex-reassignment surgery can be a tax-deductible medical expense under the Internal Revenue Code.

Last week’s decision, however, goes further: it says for the first time that when a prisoner has a legitimate medical need for gender-reassignment surgery, the state must pick up the tab. There have been a handful of cases in which inmates have sued to receive this kind of surgery — but this is the first court to order it.

Not surprisingly, the ruling has produced some outrage. Scott Brown, Massachusetts’ Republican Senator, said Kosilek’s surgery would be “an outrageous abuse of taxpayer dollars.” A niece of Kosilek’s slain wife called on the state to appeal, telling the Boston Globe: “As far as I’m concerned, he deserves nothing. If he wants to attempt suicide … let him.” Fifty state legislators have also urged the state to appeal.

So how off-the-wall is the ruling? The judge, Mark Wolf, is no far-left Massachusetts liberal. He was appointed to the bench by President Ronald Reagan and is a former prosecutor who served in the Army Reserve for six years.

As a matter of law, the court’s decision is a straightforward application of the Supreme Court’s constitutional precedents. The Eighth Amendment, which prohibits cruel and unusual punishment, requires prisons to give inmates adequate medical care. When an inmate shows that he has a serious medical need — one that poses a substantial risk of serious harm if not adequately treated — the prison has a duty to address it.

Kosilek met the legal standards that the courts have laid out. He showed that he had severe gender-identity disorder and that he suffered intense mental anguish as a result. The court found that his distress placed him at high risk of killing himself — as he had previously tried to do — if he did not receive appropriate treatment.

The court dismissed the reasons the prison gave for not providing the surgery. The prison system’s real concern, the court said, was avoiding “controversy, criticism, ridicule and scorn.” As the Supreme Court has instructed, constitutional rights must be placed beyond the “vicissitudes of political controversy.”

Many laypeople balk at the idea that a prisoner would get this sort of surgery paid for by taxpayers when law-abiding citizens do not have access to free surgery. There is an answer to this. When society puts people in prison, it takes away their ability to hold a job to earn money and get employer-supported health care. When prisoners are put in this position, the state must meet their essential needs. The Supreme Court stated only last year that a “prison that deprives prisoners of basic sustenance, including adequate medical care, is incompatible with the concept of human dignity and has no place in civilized society.”

Last week’s ruling will not produce a flood of similar court orders. Prisons are not likely to move heavily into the business of performing gender-reassignment surgery. But in extreme cases like Kosilek’s, where a failure to provide the surgery could lead to self-mutilation or suicide, providing the procedure is what human dignity and a civilized society require.