How did "Gotham" become a synonym for New York City?
If you don't have a copy of The Encyclopedia of New York City you should. It's, well, an encyclopedic reference of everything about New York, including this answer to your question:
Anglo-Saxon name meaning "goat town." It came into use after 1807, when Washington Irving used it satirically in several essays. Residents of the original Gotham, near Nottingham, England, were reportedly called "wise fools" in the Middle Ages for avoiding King John's taxes by acting insane. Although Irving seems to have used the name sardonically to suggest a city of self-important but foolish people, the perjorative connotations were gradually lost.
Have the perjorative connotations really worn off? Given the heated response many people had to the Sex and the City finale way back in February, Ask Gothamist knows plenty of people who see New Yorkers as self-important but foolish.