Lets assume a city exists underground, either in natural caves or synthetic tunnels. Are there any food sources underground, and what kind of population can they support?
The main natural sources of food energy for underground life on Earth are chemical:
Reactive chemicals, such as hydrogen sulphide gas, moving up from deeper underground. The most studied example of this on Earth is hydrothermal vents, which share a lack of energy input from sunlight with cave systems.
Less-reactive chemical weathering that can be catalysed by creatures that possess the right kinds of enzymes. These are specialised bacteria, and live life in the slow lane. However, they can literally digest rock (or at least some kinds of rock).
Chemo-synthetic bacteria can be the base of a food web supporting more complex creatures. Estimates of the biological mass vary, but could be very large due to the sheer volume of rock. However, there is nowhere near as much free energy around to support life in a given volume, as there is on the surface due to sunlight.
An underground city with enough technology has the option of generating energy to support the base of its food production. On Earth the obvious choice would be artificial lighting to grow plants. However, using e.g. nuclear fuel to generate electricity or heat, and store that energy in feedstock chemicals should work equally well.
The main problem in this scenario is the input of energy. Life on earth is fueled from the surface by sunlight. This is then turned into energy by plants, algae, and suchlike and then the entire food chain is built up from that.
Some life can live near the surface of cave networks based on the surface food web (for example it is common for animals to live in caves then emerge to forage or hunt). Cave-dwelling bats would be a classic example of this.
To have a sustained ecosystem underground you need a source of energy. Most novels set in these sort of environments (for example the Forgotten Realm's Underdark) that source of energy is magic, which fuels the growth of fungi, and then the food web grows out from that.
In a science-based universe though that is not an option so you are left with very few options:
- Mineral Consumption
- Some as-yet-unknown energy source
Reviewing these in reverse order:
Since the concept for option 3 would be a core departure from known reality there is no use speculating here. The nature of the energy source would need to be designed for the needs of the narrative world being developed and would likely be a core part of that world.
Some bacteria are capable of living underground and consuming materials from the rock around them. This is a slow and low-energy process though, you could not sustain a complex ecosystem or large animals this way.
There is a well known case of complex ecosystems on earth that are not dependent upon Sunlight. That is Hydrothermal Vents in the deep oceans.
These vents support ecosystem with bacteria at the start of the food chain, and then a procession of larger creatures all feeding off the bacteria and each other. In theory the same process could be supported underground, either in flooded caves (with non-aquatic animals then feeding off the creatures in the caves) or possibly even in dry caves.
The main hazards though would be the level of volcanic activity required to form the vents which would make caves unstable and prone to collapse. Additionally you would need some form of erosion either by lava, by water, or by some other as yet unknown action to form a cave network.