Twenty-one states led by Democrats sued on Wednesday to block a Department of Health and Human Services plan to bar federal payments from Medicaid and the Children’s Health Insurance Program for gender-transition medication and surgery to transgender adolescents.

The new rule, announced last month, is set to go into effect in October.

The lawsuit, filed in federal court in Massachusetts, argues that the new rule oversteps the Trump administration’s authority and fails to justify its restrictions. The suit said the rule violates the law by blocking reimbursements for treatments that some states have determined to be medically necessary.

“We will not stand by as the Trump administration oversteps its authority and twists the facts to justify its bad-faith agenda against transgender Americans,’’ Rob Bonta, the attorney general of California, said in a statement. “We will continue to fight to secure access to medically necessary care and protect transgender individuals’ abilities to prosper as their authentic selves.”