Mamdani’s insistence that New York is built by immigrants and now led by one taps a rich American tradition while provoking familiar anxieties