This is hardly a surprise on many, many levels. Mike Bloomberg (who I think had a lot of very real accomplishments as Mayor) has been Mayor for 12 years. Completely unexpectedly he came close to losing last time even though he had not much more than token opposition and spent like a kabillion dollars on his campaign. Not that Bill Thompson wasn't a serious candidate, he was. But no one thought it was remotely possible Bloomberg could lose so he just never got the kind of backing he might have if people had thought he had a shot at winning.
In any case, after twelve years, regardless of the merits of the incumbent, you build up huge pressures for change. That's why Christine Quinn's candidacy went down in flames. Add to that that the entire state of New York has gotten more Democratic over the last twenty years (since Giuliani was first elected) and the City has too, even if that's less a matter of party affiliation than generalized antipathy to the GOP brand.
But the really big thing is simply that it's a different city - particularly in terms of dramatically less crime and a fall off of the high-octane racial polarization of the eighties and early nineties. You can debate why crime fell. But there's no question that it was a big, big part of Rudy Giuliani's political coalition and the fact that crime dropped during (if not because of) his time in office solidified his hold on the city. Lhota's campaign is based on the idea that de Blasio is going to bring back 2500 murders a year, chronic budget crisis and even bell bottoms. But no one really buys that. So it gives a Republican little to pivot against in a a city like New York in 2013.
Joe Lhota, for those who aren't from New York and understandably haven't been following this, is the test case for the proposition that any Republican, no matter how improbable, how charisma-less,how lacking in any political following, or unable to self-fund, automatically has to win the New York City Mayor's race. Lhota's big claim to fame is having run the the New York City subway system which, despite being one of the great wonders of the world, is by definition something people like to gripe about.
This one just ain't a mystery. It's a Democratic city with pent up demand for a Democratic mayor.