A federal judge on Thursday blocked the government from restricting lawyers’ access to detainees at the U.S. military prison at Guantanamo Bay, Cuba, ruling that proposed measures would violate the detainees’ right to challenge their confinement in the courts.

In a 32-page opinion, Chief U.S. District Judge Royce C. Lamberth wrote that new Defense Department procedures would strip away a key provision of the detainees’ legal protections.

“Access to the courts means nothing without access to counsel,” Lamberth wrote, adding that “the Government’s attempt to supersede the Court’s authority is an illegitimate exercise in Executive power.”

The government sought to restrict lawyers’ access to six detainees as well as information about their cases. Two of the prisoners had lost legal challenges to their imprisonments; the others essentially were seeking to put their cases on hold while maintaining the right to consult with their attorneys about legal developments.

The new rules would block lawyers’ access to key documents and would require them to petition government authorities for access to the attorneys’ classified “work product,” Lamberth wrote. Under judicial orders, lawyers do not need permission to see such information.

The detainees’ attorneys challenged the rules, saying the restrictions would hinder their ability to help their clients. Lamberth agreed, ruling that the government did not have the authority to “unilaterally impose” such measures because judges are still overseeing the cases and the detainees “have made plain their desire to continue challenging the legality” of their confinement.

The new rules also probably would have led to “lengthy, needless and possibly oppressive delays” in the cases, the judge wrote.

Lamberth seemed perplexed that the government would issue such restrictions in light of judicial rulings and Supreme Court decisions that granted detainees the right to be represented by attorneys and to challenge their confinements in the federal courts under the centuries-old legal doctrine of habeas corpus. The judge called one government argument “preposterous” and quoted Shakespeare to critique another.

More than 160 detainees remain at Guantanamo Bay, and many have filed lawsuits in the District’s federal court to seek their release. Attorneys for detainees cheered the ruling.

“The government has never accepted the right of the detainees to effective legal representation,” said David Remes, who represents 17 of the prisoners, including two who challenged the new restrictions. “Instead of picking fights over the detainees’ access to counsel, the government should focus on what really matters — sending home the detainees it does not intend to prosecute.”

Justice Department spokesman Dean Boyd said in an e-mail that officials are “reviewing the opinion and have no further comment at this time.”