AINISSA, Syria — The two-story building here still looks much like the school it once was. But the classrooms are closed off by reinforced black doors, padlocked from the outside. And the campus is surrounded by men with machine guns seeking refuge from the desert heat in the shade of towering concrete perimeter walls.

The visitors’ echoing footsteps and voices were the only sounds on a recent day in a dusty pink-and-white hallway once filled with schoolchildren. But when a guard slid open a small window in a classroom door, a man’s face pressed against the opening. Behind him, about 15 others, sitting on mats in black sleeveless shirts, stared back.

The old school is one of about seven makeshift wartime prisons in northern Syria housing suspects accused of fighting for the Islamic State and captured by the Kurdish-led Syrian Democratic Forces. The S.D.F. prisons for male detainees — about 1,000 men from nearly 50 countries — are generally off limits, but a New York Times reporter accompanied a congressional delegation touring two of them, the first such visit to either.

The prisoners pose a dilemma that has no easy solution and that is growing urgent. Their home countries have been reluctant to take back the men. Their governments are leery that battle-hardened members of the Islamic State, also known as ISIS, might radicalize domestic prisoners. Some countries face legal hurdles to prosecuting militants if they take custody of them from a nonstate militia, as opposed to extraditing them from another government.