That's like saying "I earn $400k per year but I'm middle class because I can afford a home in Beverley Hills"
Many people well into their 30s and 40s live in NYC with roommates or a partner renting an apartment. Most of these decide to buy outside of the city but still work in it.
Though Beverly Hills is a different example since that's just an expensive neighborhood in a bigger city. I'm not talking about affording a luxury zip code. I'm talking about being able to live a "middle class lifestyle", which, at least in American culture, includes the option of home ownership in a safe neighborhood with pretty good schools.
Thing is, a lot of middle class white collar workers live here not expecting to ever have any of the above (owning a home, good schools) in the city. They know the city is expensive and home owners here have either been here for decades or are wealthy.
They're here until their mid 30s when they move to a suburb. What I am saying is, a lot of middle/upper middle class people don't care that they can't buy a house in NYC - they were never expecting to.
I would also argue that the middle class lifestyle you describe is not as popular as before.
--
The areas in NYC that are affordable to own a home in are not much further away from jobs than areas where one can get a bigger house and not live in 100 year old, poorly maintained building. People will choose to commute an hour away from upstate, Long Island, or even Connecticut than still live in the city 40 mins from work in a smaller, older building.