Why questions are tricky, but here goes: Treatment of a municipality as a corporation seems a result of the incremental reform in government.
The City of London is historically important in that the Magna Carta of 1225 granted it special recognition, in English (translated from the original Latin):
The City of London shall enjoy all its ancient liberties and free customs, both by land and by water. We also will and grant that all other cities, boroughs, towns, and ports shall enjoy all their liberties and free customs.
That's great, but in a society of feudalism and monarchy, what legal entity is this talking about? Some nobleman, a bishop? No, it seems significant that by this time the Lord Mayor of London was elected and associated with a livery company. Livery companies evolved from guilds into corporations under royal charter which established personhood on entities that were not natural persons.
To this day, livery companies and liverymen play a significant part in the governance of the City of London. To some the situation seems even more odd when you consider that only liverymen can vote to elect the Lord Mayor of London, but it is well worth noting that the Lord Mayor is a separate and distinct office from the Mayor of London. Lord Mayor is more a ceremonial role; not too surprising in a country that distinguishes between the head-of-state and head-of-government.
As to limitation of liability, sure that's part of it. The idea of corporate liability limits the vicarious liability of any people associated with a corporation. But a corporation doesn't necessarily have stockholders who are escaping liability yet entitlement to profits by creating a "stock corporation". That's the form of corporation most people think of today, but it is a substantially newer development than London.
In the US, we draw a distinction between incorporated areas and unincorporated areas. For example, I once lived in the unincorporated area of Silver Spring, Maryland, which while having tall buildings and a population large enough to be considered a city has no local government aside from the county it is located in.
Finally, it's important to draw a distinction between an incorporated area and a company town, where practically all stores and housing are owned by the one company.