A yearslong challenge for the left was starkly illustrated this week as its hopes faded in the New York mayor’s race.