Before you can place a town or city, you must first have a world to place it in. When building your world you will need to determine general aspects that apply to your entire world, such as gods and their religions, races and their cultures, empires and their locations and other questions beyond the scope of this question. Once you have your world, you then want to create some general tables for different aspects of the hamlet/town/city you want to place.
Develop tables for describing and possibly randomly determining different factors. Note that some of the factors will not apply to any but the largest cities, but having them allows you use them for flavor in smaller settings, such placing either a government in exile or an assassins guild in an isolated hut somewhere.
Tables for the town or city you are building:
Differing town sizes:
- isolated hut
- isolated shop/tavern, possibly with a few houses
- small hamlet
- capital or important large city
- abundance or lack of local water transport
- abundance or lack of mineral resources (mining town/trade-town)
- abundance or lack of fresh water
- abundance or lack of good farmland. Clay soil? Sandy soil?
- forested? Desert? Swamp? Rock slab? Volcano? Glacier?
- how long ago was the town/city founded?
- what races make up it's population (and what cultures did they come from?)
- nearby nations or empires, and their relations
- commerce: who trades with them, what do they have/desire to trade?
- What religions are represented locally?
- who are your neighbors? Evil empire? Necromancer? My little pony?
Now build smaller template tables for substructures to place in town:
Once you generate buildings and arrange them pleasingly in your city,
think of how the tables above interact with one another. You may have a mining town that is landlocked, has little trade, and poor farmland. This will tend to drive food prices sky high, which won't be helped by the new law that restricts imported foods types that are acceptable to the local temple, but the population won't have time to starve due to the plague problem drifting in from the nearby swamp and the fact that the local mayor is recruiting everyone not nailed down to provide cannon fodder for defense from the recent zombie invasion.
You can assume generic NPCs for the most part, but you will still want to place some quirky NPCs for flavor, random encounters, and also as agents or henchmen for your planned Big Bad. But NPC generation is also outside of the scope of this question, so I'll leave my answer at that.