When Abdulrahman El Bahnasawy, then an 18-year-old from Canada, was arrested in May 2016, he was secretly detained in New York by federal authorities who hoped to arrest others in a supposed plot to detonate bombs in Times Square and in the subways.

Although federal authorities did eventually arrest two other men, Mr. El Bahnasawy’s time in custody did not go exactly to plan.

Shortly after his arrest, jail officials mistakenly moved him into the general population of a federal detention center in Manhattan, instead of holding him in isolation. That lasted one day — long enough for him to have money stolen from his commissary account.

Several months later, after being allowed to move into the general population, Mr. El Bahnasawy was given drugs by another inmate, leading to more complications.