U.S. District Judge Royce Lamberth said in his ruling a federal law prohibits prison officials from arbitrarily depriving inmates of medications and other lifestyle accommodations that the bureau’s own medical staff has deemed appropriate.

The judge said the transgender inmates who sued to block Trump’s executive order are trying to lessen the personal anguish caused by their gender dysphoria, the distress that a person feels because their assigned gender and gender identity don’t match.

“In light of the plaintiffs’ largely personal motives for undergoing gender-affirming care, neither the BOP nor the Executive Order provides any serious explanation as to why the treatment modalities covered by the Executive Order or implementing memoranda should be handled differently than any other mental health intervention,” the judge wrote.