Senator Bernie Sanders of Vermont backed Mr. Mamdani, joining Representative Alexandria Ocasio-Cortez in endorsing the front-runner of progressives.