Mr. Hassan hung his head and admitted it, then looked up. “I was only a cook.”

The lieutenant laughed good-naturedly. “Tens of them tell me they were cooks,” he said. “They had so many cooks, you’d think all they did was eat.”

The Iraqi offensive against the Islamic State in Hawija began on Sept. 21 and is now in its final stages, Iraqi officials say. The army and police, backed by Shiite militias, are close to retaking the city, which is believed to still have 78,000 residents — and up to 3,000 Islamic State fighters.

Iraqi Kurdish officials are intent on identifying any known fighters among the arriving men who may be linked to atrocities. Any with charges against them would be sent to court, while the others would eventually be allowed to rejoin their families in camps inside Iraq’s Kurdish region.

The men were first stripped of their shoes, belts (which in most cases were just string or rope), turbans and any belongings, then made to kneel in rows in a large tiled room, their heads bowed forward.