Mr. Dost, a dour but quick-witted man who was known for the poetry he etched into the side of coffee cups for lack of better writing materials, was adamant that there was only one course of action after their release: Go to Pakistan and start waging jihad. He spoke of uniting the whole Muslim world.

Mr. Ghalib had other plans. “I used to argue with them that we are Afghans and we must support Afghanistan,” he said, meaning the current, American-backed government that replaced the Taliban. It was the minority view, but he did not worry about sharing it with Mr. Dost or any of his jailed countrymen. “We were friends with each other despite our views,” he said.

How Mr. Ghalib ended up in American captivity is its own bewildering story. After building a reputation as an effective commander against the Soviets and the Taliban, he became a police chief for the new Afghan government after the Taliban’s ouster in 2001. But in 2003, he was arrested after United States soldiers found explosive devices adjacent to the government compound where he worked. That was apparently close enough. There were also several letters that linked him to Taliban figures, although American officials conceded the letters might have been forged.

One of the military officers weighing the evidence against him explained that he did not “put much credibility to any of these letters,” according to a transcript of the tribunal.

That left Mr. Ghalib flummoxed. “So why are you detaining me?”

At Guantánamo, Mr. Ghalib often explained to his captors that he had been fighting the Taliban for years and had even aided American forces at Tora Bora against Al Qaeda. He recited the names of major anti-Taliban commanders who would vouch for him.