BOSTON — A federal appeals court on Friday upheld a judge’s ruling granting a taxpayer-funded sex change operation for a transgender inmate serving a life sentence for a murder conviction, saying receiving medically necessary treatment is a constitutional right that must be protected “even if that treatment strikes some as odd or unorthodox.”

U.S. District Judge Mark Wolf ruled in 2012 that the state Department of Correction must provide sex reassignment surgery for Michelle Kosilek, who was born as Robert Kosilek and is serving a life sentence for the killing of his wife in 1990.

The Department of Correction challenged the ruling at the 1st U.S. Circuit Court of Appeals. Its lawyers argued Kosilek has received adequate treatment for gender identity disorder, including female hormone treatments, laser hair removal and psychotherapy. Prison officials said those treatments have eased the stress and anxiety felt by Kosilek, and they argued it was unnecessary to heed advice from independent medical experts who recommended the 64-year-old undergo the sex change surgery as the next step of treating her intense gender identity disorder.

The Department of Correction also argued prison officials were concerned about protecting Kosilek, who’s in an all-male prison, from sexual assaults if she were allowed to complete her transformation into a woman.

U.S. 1st Circuit Court of Appeals Judges O. Rogeriee Thompson and William Kayatta Jr. said in their ruling they were “assuredly mindful of the difficult tasks faced by prison officials every day.”

The Supreme Court has cautioned that while sensitivity and deference to these tasks is warranted, “(c)ourts nevertheless must not shrink from their obligation to enforce the constitutional rights of all persons, including prisoners,” the two judges wrote. “And receiving medically necessary treatment is one of those rights, even if that treatment strikes some as odd or unorthodox.”

One member of the three-judge appeals panel disagreed. Judge Juan Torruella said in a separate opinion the ruling went beyond the boundaries of protections offered under the Eighth Amendment.

Still, Kosilek’s lawyer Joseph Sulman said they were very happy that her right to receive the treatment was affirmed.

“This decision is really about more than sexual reassignment surgery,” Sulman said. “It’s about the state’s requirement to treat all prisoners equally regardless of their gender identity or regardless of the circumstances.”

Democratic Gov. Deval Patrick had no immediate comment on the appeals court ruling or whether a further appeal to the U.S. Supreme Court was possible, a spokeswoman said.