WASHINGTON — A federal judge on Thursday blocked the government from transferring an American citizen accused of fighting with Islamic State militants to Saudi Arabia, meaning he will stay for now in a U.S. military detention facility in Iraq.

The Trump administration has been holding the unidentified citizen without charge since he surrendered on the Syrian battlefield more than seven months ago. The detainee's legal quandary has become a test case for how the government should treat U.S. citizens picked up on the battlefield and accused of having ties to IS extremists battling America and its allies.

The man, who once lived in Louisiana, was being detained as an enemy combatant. Court documents filed by the government say that when he surrendered to U.S.-backed Syrian Democratic Forces, he was carrying thumb drives containing thousands of files. There were 10,000 or more photos — some depicting pages of military-style manuals. There also were files on how to make specific types of improvised explosive devices and bombs.

The American Civil Liberties Union, which is representing him, claims he was in Syria to chronicle the conflict and was trying to flee the violence when he gave himself up in September. The ACLU claims the government has not provided any evidence that he took up arms against the United States and notes that he was imprisoned by the IS group. The detainee said he had press credentials to do freelance writing about the conflict in Syria, though the FBI says it hasn't found any published articles or blogs he wrote.

Get Breaking News Delivered to Your Inbox

The government notified the court this week that it wanted to transfer him to a third country. The government did not name the country, but a U.S. official told The Associated Press that he was slated to be transferred to Saudi Arabia, where he has dual citizenship. The official was not authorized to discuss the issue and spoke on condition of anonymity.

The ruling was a victory for the ACLU. Jonathan Hafetz, an attorney for the group, argued that any transfer would violate the detainee's constitutional and legal rights because the government has not charged him or proved that it legally detained him in the first place.

"The government cannot do whatever it pleases with a U.S. citizen," Hafetz said following the ruling. "After over seven months of imprisonment, the government should either charge or release him. That's how our justice system works."

The ACLU's challenge to the legality of his detention is still pending in federal court. U.S. District Judge Tanya Chutkan ruled that the government cannot transfer him without a subsequent order from the court.

In morning open and closed court sessions, it was clear that Chutkan was not embracing the government's argument to transfer him.

She said the government was asking her to allow the U.S. to send an American citizen who has not been charged with a crime to another country. She said there was no indication as to when or if the receiving country would ever release him.

The government acknowledged that the receiving country could continue to hold the detainee for as long as it determined was necessary.

James Burnham, a lawyer representing the government, said that the receiving country has a strong interest in the detainee and that U.S. relations with the nation could be harmed if the transfer is not allowed to go through.

"It's not release if you are just giving him to another jailer," the judge said.

The government claims presidential authorities as well as congressionally approved war powers written after 9/11 provide the legal basis to hold the detainee as an enemy combatant linked to the IS group. The ACLU argues those war powers pertain to al-Qaida and the Taliban and don't apply in the battle against IS.

In an earlier ruling, the judge ordered the government to provide 72 hours' notice before transferring him. She issued her ruling Thursday about 15 minutes before the 72 hours was set to expire.