A city name helps when the page carries genuinely local content for a real service area, and it tips into doorway spam the moment you are stamping the same content with swapped city names. The line runs through unique local value per page, not the presence of the city name itself. Naming a city is fine, even useful, when the page has something specific to that place to say. It becomes spam when the city name is the only thing that changes across otherwise identical pages, because then it is signaling location without delivering any local substance.
On the helpful side, a city name is a real local relevance signal when the content backs it up. A page about your service in a particular city that includes locally distinct details, the actual area you serve, real projects or examples there, references that make sense to someone in that place, tells both users and search engines that you genuinely operate there. The city name is doing honest work because the page genuinely is about that location. That is the kind of local signal that helps.
On the spam side, the failure is the swapped template. Duplicate one page across twenty cities, change only the city name in the heading and a few lines, and you have built doorway pages, pages created to rank for a location without offering anything unique to it. Search engines specifically target this pattern, because it is the city name pretending to be local content. Stamping the name everywhere with nothing local behind it is the reflex to avoid; it adds risk, not relevance.
So the pivot is always whether the page offers unique local value. Can a reader in that city get something from the page that a reader in the next city over would not, beyond the name swap? If yes, the city name is earned. If no, the page should not exist as a separate location page at all, and adding the city name only makes the duplication more obvious.
When you decide where to use city names, give each location page genuinely local content, real service details, local proof, place-specific information, or do not make a separate page for that city. Use the city name where the page truly is about that place, and never as a find-and-replace across copies of one page.