Mamdani, a democratic socialist who took office in January, has amassed a large following on social media and among younger residents.