The ruling was issued in the case of Omar Khadr, 21, which could become the first to go to trial at the Guantanamo Bay Navy base in southeast Cuba as soon as the spring.
The law authorizing the first American war-crimes tribunals since the World War II era allows the use of classified evidence, and some parts of trials are expected to take place in closed courtrooms.
But Khadr's lead attorney, Navy Lt. Cmdr. William Kuebler, protested the order against revealing witnesses' identities, saying it will make it harder to investigate their claims and force him to keep secrets from his client.
"It interferes with defense counsels' ability to form a relationship of trust and confidence with the accused," Kuebler wrote to the judge, according to documents released by the Pentagon this week.
The judge, Army Col. Peter Brownback, issued the order Oct. 15 following a request by military prosecutors, who argued witnesses should be protected from possible terrorist retaliation.
"It is conceivable, if not likely, that al Qaeda members or sympathizers could attempt to target witnesses," wrote Marine Corps Maj. Jeffrey Groharing, the lead prosecutor in the case.
Khadr, who was 15 when he was captured in Afghanistan in 2002, is accused of throwing a grenade that killed Sgt. 1st Class Christopher Speer, a Delta Force commando, after a firefight at an al Qaeda compound. Many of the witnesses at his trial are expected to be U.S. service members who participated in the raid.
Ben Wizner, a staff attorney for the American Civil Liberties Union, said Saturday that the judge's order would deny Khadr the opportunity to provide information that could challenge the credibility of his accusers.
"Khadr's case may be the very first trial under this new system, and if the trial is conducted with rules that don't allow him to defend himself, the system will be seen as illegitimate and U.S. interests will be harmed," Wizner said.
A Pentagon spokesman, Navy Cmdr. Jeffrey Gordon, said Saturday the order was needed to protect the lives of key witnesses.
"Military Commissions have been designed to be open and transparent while at the same time protecting national security and the safety of our military men and women," he said.
The judge's order and the attorneys' arguments were released among nearly 700 pages of previously unavailable documents related to Khadr's prosecution. Last month, five news organizations including The Associated Press complained they were being denied access to much of the military commission proceedings.
Khadr is one of three Guantanamo detainees facing charges under the Military Commissions Act. The military has said it plans to prosecute as many as 80 of the 305 men held at Guantanamo.