The suspect, a 19-year-old Pole, had become “infatuated with Islam” and wanted to carry out an attack on behalf of Islamic State.