Mayor-elect Zohran Mamdani, gregarious with constituents and vilified by a range of critics, is taking office at a time of anxiety about political violence.