(CNN) After two days of walking in the Syrian desert, one fitful night sleeping in a mud hut and a failed attempt to bribe a local into vouching for him to get safe passage out of ISIS territory, it looked like the man was en route to freedom on the back of a water truck.

But when the truck reached a checkpoint near Abu Khashab guarded by Syrian Democratic Forces, a soldier spotted the man and asked him to climb down, according to court documents.

The Kurds had set up the checkpoint to stop Islamic State fighters from fleeing the area by hiding with groups of refugees. The soldier was suspicious of the man, who had a long beard, stylish clothing and a duffel bag containing a Quran, a GPS device, flash drives, $4,210 in cash and, oddly, a snorkel mask and a scuba certification card.

Among the files on the flash drives were bomb-making manuals and an array of Arabic spreadsheets, including one named "Islamic State Spoils and Booty Bureau."

It was on or about September 11, 2017, when the Kurdish soldiers apprehended the man, according to court filings. He told his captors he was a US citizen and asked them to take him to the Americans. The Americans took him to a safe house for two days of interrogations by government agents.

He said he had journeyed to Syria as a freelance journalist and was kidnapped by ISIS within days of crossing the border from Turkey. He denied that he was a fighter and said he had made multiple escape attempts over 30 months in the terror group's self-declared caliphate.

After telling the agents his story, the man was blindfolded and transported via helicopter to a military prison at a classified location in Iraq, where he has been locked up for more than nine months as an alleged enemy combatant.

In a federal courthouse 6,000 miles from Iraq, there's an ongoing dispute over the fate of the mysterious detainee caught in the desert with scuba gear and ISIS spreadsheets. In court documents, the prisoner is called John Doe because of the secrecy surrounding the case. Doe has yet to be charged with a crime.

The American Civil Liberties Union argues that the Department of Defense should either bring Doe to the US for prosecution or release him. It's a case straight out of TV's "Black Mirror," with ACLU lawyers encouraging the government to arrest their client.

Keeping an American citizen in military custody abroad is a violation of due process rights, according to the ACLU. The organization filed its petition for a writ of habeas corpus at the US District Court for the District of Columbia last October.

The government says the Authorization for Use of Military Force passed by Congress in 2001 gives the executive branch wide latitude to detain individuals, including American citizens, captured on the battlefield to prevent acts of terrorism.

The problem, according to the ACLU, is that there's no end point to the war on terror, so the military can imprison someone indefinitely. The government's burden of proof goes out the window if a detainee isn't permitted to challenge the factual basis for his designation as an enemy combatant.

Airstrikes on the Islamic State began in 2014 and at the time, the Obama administration reasoned that the military could carry out attacks without congressional approval because the 2001 Authorization for Use of Military Force covered groups associated with al Qaeda. ISIS evolved out of an al Qaeda splinter group.

In a 147-page court filing, the Defense Department presented its evidence that Doe had provided material support to the Islamic State. The overview is heavy on internet search histories and social media postings. Between January 2014 and March 2015, according to the Defense Department, Doe looked up ISIS videos on YouTube 859 times. He sent 22 tweets to an Islamic State propaganda account, posting pictures of the group's flag and denouncing "infidels." In one tweet, he declared, "Let's unite that the word of God may be realized in us and that we may cut off the hand and cut out the tongue of the troublemakers."

Although an internal ISIS intake form recovered during military operations lists Doe as a fighter, he said he was never much of a mujahedeen due to back problems. He told government agents he spent his first seven months in Syria jailed by ISIS. At some point, he was released on the condition that he work for the terror group. Doe then registered as an Islamic State recruit, swore an oath and went to a Sharia training facility.

While living in the caliphate, Doe served in various administrative roles. He described a life of banal chores rather than battlefield savagery. Doe guarded an oil field, gassed up vehicles and monitored prayer services. At one point, an ISIS commander asked him to help build a device that could take down airplanes via microwaves. Doe said he refused to work on the project. Instead, he paid the Islamic State $750 to rent a 200-acre farm in Hamah, planting almond and olive trees, tending to a flock of 80 sheep. He envisioned himself starting a new life as a shepherd across the border in Turkey. The looming danger of airstrikes motivated him to sell his sheep, flee the farm and try to escape via water truck, Doe told the interrogators.

While other American travelers suspected of ISIS support have been extradited to the US and charged in criminal court, there are no signs the government intends to prosecute Doe. In April, the Defense Department said it was prepping to transfer him to authorities in an unnamed third country. The third country is likely Saudi Arabia, where Doe holds dual citizenship, according to court documents. The transfer was stopped by a district judge. An appeals court panel upheld her ruling.

This month, the government made another proposal. The Defense Department wants to take Doe back to Syria and free him in the desert close to the area where he was captured. He'll get back the cash that was confiscated from his duffel bag and the government is planning to provide him with a new cellphone and weather-appropriate clothing, as well as food and water to last several days. The whereabouts of Doe's passport are unknown and travel documents are not part of the deal. US District Judge Tanya Chutkan expressed concern about the scenario during a June 8 status hearing.

"You're proposing releasing him to a country which is in the middle of a civil war and where suspected ISIS fighters have been executed or tortured, and you propose doing that with a US citizen who has no way of proving that he's a US citizen, no identification whatsoever," said Chutkan, of the District of Columbia. She also questioned why the government was publicizing that it is giving Doe cash, making him a potential target for thieves.

The next court hearing is set for July 13.

"The government had three options: give an American citizen his day in court to challenge his detention as an enemy combatant, charge him with a crime and give him a trial, or release him," said ACLU attorney Jonathan Hafetz in an emailed statement. "By seeking to release our client, albeit an unsafe release to war-torn Syria, the government has effectively conceded that it has no reason to continue detaining him and that he does not pose a threat. It also speaks volumes about the weakness of the government's factual assertions and the flaws in its legal justification for holding him."

The ACLU took on the case because no one else came forward to challenge Doe's detention in court. Typically, a family member files a petition as a "next friend." The Defense Department objected to the ACLU representing Doe because the organization had no ties to him and its attorneys could be driven by a political agenda rather than serving the interests of their client. After three months of hearings and motions, Chutkan allowed the ACLU's attorneys to make contact with Doe.

When Doe went to Syria, he abandoned his wife and daughter, who turns 4 this month, according to court documents. He communicated with his wife throughout most of his time in ISIS territory but shortly after he fled the farm, the couple had a fight because she had traveled without telling him. That was the last time they spoke before his capture. During his ill-fated attempt to reach Turkey, he texted his sister and asked her to wire money. Doe waited for a week and gave up, taking his chances with his cash on hand.

The last high-profile case involving an American detained overseas and declared an enemy combatant went all the way to the Supreme Court. Yaser Hamdi, a dual citizen of the US and Saudi Arabia, was captured in Afghanistan in 2001. The government accused him of fighting for the Taliban and he was initially taken to the US military prison at Guantanamo Bay.

When his American citizenship was confirmed, the Defense Department moved him to a Navy brig in the Southeastern US. Hamdi's father filed a habeas corpus petition on his behalf and the Supreme Court decided in 2004 that holding him in military custody violated his constitutional rights.

"Due process demands that a citizen held in the United States as an enemy combatant be given a meaningful opportunity to contest the factual basis for that detention before a neutral decisionmaker," Justice Sandra Day O'Connor wrote in the majority opinion. Ultimately, Hamdi cut a deal to renounce his US citizenship and return to Saudi Arabia rather than go to trial.

Although the government cites the Hamdi case extensively in its filings, the new case is different because Doe opposes a transfer to Saudi Arabia or Syria. Hamdi voluntarily renounced his US citizenship as part of a deal with prosecutors.

"We know of no instance, in the history of the United States, in which the government has taken an American citizen found in one foreign country and forcibly transferred her to the custody of another foreign country," two judges from the US Court of Appeals for the DC Circuit wrote in their opinion stopping Doe's transfer to Saudi Arabia. (A third judge on the panel dissented.)

"Under the logic of the government's position, it could pick up an American traveling in Europe and involuntarily relinquish her to, say, the custody of Afghanistan, as long as Afghanistan is thought to have some cognizable sovereign interest in her," wrote the judges. "We cannot conclude that the government possesses that kind of authority over a US citizen."

What gets lost in all the legal wrangling over the separation of powers and the lineage of ISIS is the lingering mystery of Doe's motives. Did he go to Syria as a citizen-journalist, as he claims, or were his intentions more sinister?

An unnamed friend interviewed by the FBI described Doe as someone who could easily be misled and recruited into a terror group. Doe was enraged by the atrocities committed by the Syrian government and may have been deluded into thinking the Islamic State was fighting for a righteous cause, his friend said.

Doe attended college in New Orleans circa 2005-2006, his friend said. While at school, Doe liked going out drinking, smoking pot and hitting the casinos. He frequented strip clubs, spending money he received from the Saudi Arabian government, according to his friend. Doe eventually graduated with a degree in electrical engineering and moved to Saudi Arabia, where his family owned a construction company and a tailoring shop. He settled down and got married in 2008. He began tweeting his support for the Islamic State in 2014, according to the Defense Department.

There's no mention in the court filing of whether the friend was paid by the FBI like an informant. It's also not clear if the friend contacted the authorities when he first suspected Doe had been radicalized.

The friend told the FBI that Doe was "very smart, but not smart enough" to recognize that ISIS "was not the solution."

This post has been updated.