WASHINGTON—Under pressure from a federal court, the Pentagon on Friday released a Marine Corps general who was put under house arrest for disobeying what he said was an illegal order that would compromise a fair trial for a Guantanamo detainee facing a potential death penalty.

Brig. Gen. John Baker, the chief defense counsel for the military commission system at Guantanamo Bay, had been sentenced to 21 days’ detention and a $1,000 fine by a military judge angry that he allowed civilian defense attorneys to resign from a case. They withdrew after apparently discovering the government secretly had been monitoring their communications, including legally-privileged exchanges with their client.

The Defense Department released Gen. Baker a day after his attorneys filed a petition with the U.S. District Court arguing the military judge had no authority to punish the Marine officer. At an emergency hearing Thursday, government authorities asked U.S. District Judge Royce Lamberth to avoid ruling on the petition while the head of the military commission apparatus, Harvey Rishikof, considered the matter.

When Judge Lamberth reconvened proceedings Friday afternoon, the government said Mr. Rishikof, whose title is “convening authority,” had decided to “defer” Gen. Baker’s punishment while weighing the arguments.

Judge Lamberth said the decision to release Gen. Baker “was a wise one.” He said he would allow Mr. Rishikof “a reasonable time” to resolve the matter, but invited defense lawyers to return to his court if things drag out.