As the Islamic State’s self-declared caliphate collapsed in Syria, tens of thousands of men, women and children who had lived in it ended up in squalid camps and crowded prisons run by the Kurdish-led militia that had partnered with the United States to defeat the jihadis.