In early 2003, military investigators traveled to Guantánamo Bay, Cuba, to interview one of the prison camp’s most valuable detainees, a Qaeda loyalist from Morocco named Abdullah Tabarak. According to multiple reports, Mr. Tabarak had been Osama bin Laden’s chief bodyguard and longtime confidant, and he gave himself up to help bin Laden elude capture shortly after the Sept. 11 attacks.

But when the investigators arrived, Mr. Tabarak wasn’t in his cell. The guards would not say where he was. His disappearance was so mysterious that one investigator took to calling him “the milk carton guy.”

In August 2004, news reports from Morocco revealed he was back home in Casablanca. The Bush administration never explained the release, but, as Jess Bravin documents in “The Terror Courts,” his comprehensive account of the legal — and more often extralegal — events that have taken place at Guantánamo since 2002, it appears political expediency played a crucial role. Morocco had, among other things, hosted a C.I.A. “black site” and interrogated suspects secretly deported by the United States.

Republicans continue to rail against President Obama’s trade of five Taliban detainees for Sgt. Bowe Bergdahl on May 31, but prisoner releases in wartime are never simple or clean.