The two Turkish men shuffled into the courtroom, their closely cropped hair, clean-shaven faces and chubby waistlines hardly the look of fearsome fighters of the Islamic State.

Appearing in court for the first time since being arrested in August on charges of belonging to that group, they professed their innocence, telling the judge they were simply plumbers who migrated to Iraq from Turkey looking for work.

After an 18-minute trial, they were sentenced to death by hanging.

The men are among hundreds of foreigners detained in Iraq on terrorism charges after the toppling of the Islamic State’s self-declared caliphate. The defendants — men, women and children hailing from Asia, ­Europe and Africa — are coursing their way through Iraq’s criminal justice system, often receiving harsh sentences in rapid-fire trials.

The trials and capital sentences are presenting foreign governments with a moral and political dilemma. Do they object to the Iraqi trials and claim their citizens, who could threaten their home countries and radicalize others if repatriated? Or should Iraqi courts be allowed to determine the defendants’ fate in trials that human rights groups and the United Nations say are deeply flawed?

The issue has taken on new urgency as major combat against the Islamic State ended this month. Iraq has fast-tracked executions under the year-old orders of Prime Minister Haider al-Abadi, aiming to “give comfort to the families” of the Islamic State’s victims.

[Iraq declares complete victory in the war against Islamic State]

Iraq’s Justice Ministry has disclosed 194 terrorism-related executions since 2016, including at least 27 foreigners from other Arab countries, according to a review of ministry news releases.

On Dec. 14, the ministry said it had executed an additional 38 prisoners on terrorism-related charges, but it did not specify their nationalities, prompting a rebuke by the United Nations human rights office. At least one of those executed had Swedish citizenship, according to researchers on human rights and terrorism.

Up to 6,000 more are on death row, and their nationalities have not been disclosed, according to the United Nations. Many more suspected militants are in custody, including at least four Europeans.

European countries have given little indication that they want to claim their citizens.

In a statement, Turkey’s Foreign Ministry said it is aware of Turkish citizens being detained in Iraq for allegedly joining the Islamic State. “We are in touch with the Iraqi authorities in terms of finding out their whereabouts and ensuring their repatriation,” it said.

The United Nations said last month that Iraq does not have jurisdiction to try Islamic State atrocities and that Iraqi investigators, prosecutors and judges do not have the capability to ensure due process. It urged Iraq to turn to the International Criminal Court for such cases, especially those dealing with the attempted genocide of minority groups such as the Yazidis whose reintegration into Iraqi society largely depends on the accurate prosecution of crimes committed against them.

Iraq’s massive dragnet is ensnaring scores of innocent people, while rushed investigations and trials are failing to distinguish between Iraqis who embraced the Islamic State and others who cooperated with the group out of fear or coercion, human rights groups and the United Nations said.

The lack of due process could imperil national reconciliation by enshrining a cycle of revenge in Iraq’s courts, these groups said. This dynamic raises the possibility of continued sectarian conflict between Shiites, who dominate the government and legal system, and Sunnis, who account for nearly all those accused of terrorism.

But Abdulsattar Bayraqdar, a senior Iraqi federal judge, bristled at the criticism, saying his country’s judges and lawyers have sacrificed their lives to guarantee fair trials and hold terrorists accountable. He said that since 2003, at least 60 judges and more than 160 investigators and court employees have been killed in terrorist attacks stemming from their work.

As for foreigners affiliated with the Islamic State, Bayraqdar said that crimes committed by extremists on Iraqi soil must be prosecuted in Iraq, and that it is under no legal obligation to hand over suspects or convicts to other countries.

“But those who are acquitted are being handed over to their countries,” he said.

'Judge with justice'

The single courtroom where terrorism trials are heard is spartan. An imposing wooden cage sits in the middle of the room. From behind the bars, defendants face a panel of three judges on a high bench. Behind the cage are three rows of benches, typically occupied by lawyers. Defendants’ families are not allowed in the room.

The walls are bare except for a small banner above the judge’s heads imprinted with a partial Koranic verse: “When you judge between people, judge with justice.”

On Dec. 14, after court clerks finally located a Turkish-language interpreter, the Turkish defendants were brought in wearing faded brown jumpsuits.

The lead judge, Suhail Abdullah, eyed their charge sheet, confirming their identities: Ramadan Hassan, 24 years old, and Talat Yakout, 40 years old. The judge advised them that they were charged under Iraq’s anti-terrorism law with joining the Islamic State and said they would be provided a lawyer at the expense of the state.

A lawyer from the audience stood up and accepted papers from the bailiff, hurriedly reviewing them as Abdullah recounted how the men had been taken into custody.

They had been arrested by soldiers while trying to flee Tal Afar, a western city near the border with Syria. They allegedly tried to blend in with hundreds of families fleeing the city as Iraqi forces stormed it to evict Islamic State militants.

[Iraqi military reclaims city of Tal Afar after rapid Islamic State collapse]

Next, reading from what he said was their confession to investigators, the judge described Hassan and Yakout as small-time operatives for the Islamic State when they illegally entered Iraq in February 2014. He said they had admitted to coming to Iraq to fight.

The defendants, whispering to their interpreter, denied the charge. They said they had come to Iraq to make money. They argued that they had never engaged in combat for the militant group.

“But that’s your testimony, right here,” the judge shot back.

“I said that after being tortured,” Hassan said. “I came to Tal Afar to only work as a plumber.”

“Welcome, welcome,” Abdullah said sarcastically. “You expect me to believe you came to Tal Afar while it was occupied by Islamic State to work as a plumber?”

Yakout offered a similar defense, pointing to their surrender to the Iraqi army as evidence of their innocence.

“Of course you surrendered, because time had run out,” the judge said.

Their lawyer, given the opportunity to speak, simply asked the court to acquit them, saying there was no evidence except the confessions that were extracted through torture.

Hassan and Yakout were taken away to await the verdict.

A difficult defense

Iraq’s anti-terrorism law gives judges wide berth in deciding cases. Prosecutors must show that a defendant joined or supported a terrorist group but are not required to prove a specific charge of murder.

In a report released this month, Human Rights Watch said prosecutors and judges were ­doing little to distinguish between fighters and others who did menial jobs for the Islamic State, such as cooks.

But Bayraqdar, the senior judge, defended the legal process, saying every member of the militant group contributed to a cohesive unit that terrorized Iraqi citizens. He added that a terrorism trial is not a simple formality. In November, he said, trials resulted in 449 convictions and 1,490 acquittals.

In the hallways outside the courtroom, lawyers wearing black robes with emerald-green trim busily roam the halls, quizzing prison guards and bailiffs on the whereabouts of their clients.

The defense lawyers say they never know whether they will get access to their clients or when they will appear. Defendants often are brought to court without notification. The lawyers complain that they are not present when their clients are interrogated and that the suspects often are tortured into making false confessions. Court files often disappear, only to be found after a defendant has been convicted.

“With any civilian case, I can do what I want, defend them in the way they should be,” said Nazhan Taha, a private attorney in Baghdad. “But with terrorism cases, I’m limited.”

The pressures that defense lawyers face is most extreme in cases involving detainees who allegedly were involved with the Islamic State in Mosul, which was liberated after an especially deadly nine-month fight.

[Iraqi forces declare victory over ISIS in Mosul, but fighting continues]

“You will be questioned, arrested or killed for taking one of their cases,” Taha said.

Cigarette smoke lingers in the hallways of the court, with smokes being passed among prison guards, lawyers and even the defendants held in two cages at the end of the corridor.

The guards and bailiffs allow the detainees’ families to briefly exchange furtive and tearful kisses with the defendants between the yellow prison bars. But they are gruff with the defendants themselves.

One bailiff shared that he had lost his brother, a police major, in the fight to reclaim Mosul.

“And now I look after the ones who killed him,” he said, pointing to his eyes, an Arabic expression of duty and selflessness.

'I condemn you'

While the two Turks waited to learn their fate, the panel of judges heard nine more cases involving a variety of alleged crimes.

Among the defendants were two Turkish sisters, Raja and Najla Tahseen, age 32 and 27, whose husbands were accused of having been minor administrative officials for the Islamic State in Tal Afar.

The women were briefly questioned by the judge and claimed to be housekeepers whose husbands eventually quit the militant group. The women appeared nervous and confused. Their court-appointed lawyer asked the judge to show “mercy, because they are women.”

A few minutes later the judge barked, “Decisions!” All the defendants were herded back into the room.

He called the Tahseen sisters forward and sentenced them to life in prison.

Then he called Hassan and ­Yakout.

“I condemn you to hang until death,” the judge said, not lifting his eyes from the papers in front of him.

Read more:

Today’s coverage from Post correspondents around the world

Like Washington Post World on Facebook and stay updated on foreign news