Any Democrat with openly leftist views that tries to burst into the mainstream is almost always actively squashed by the Party. Bernie had too much longevity and popularity to be cast aside, but they for sure couldn't allow him to be the nominee, at the cost of giving the world Donald Trump. AOC and Mamdani are outliers that have thus far been able to weather the anti-leftist hostility that is endemic to the Party by appealing directly to their constituents rather than simply parroting the Party lines, for the most part.
Mamdani employed the super radical strategy of talking directly to his potential constituents, absorbing what policies they wanted from their mayor, and then running directly on those policies. It turns out, when you do that, it's difficult for the Party apparatus to eject you, even when they try their best, as they did and are.