This is quite broad question, in fact the full answer to your question would probably require a textbook on urban economics, so also this answer is based on one; Brueckner (2011) Lectures on Urban Economics, MIT press, which is whole book largely dedicated to this (and other urban economics) issue(s). I will try to provide summary of main arguments found in the source cited above and also some additional ones. According to economic theory there are several reasons for urban areas cities to develop
Specialization/division of labor - the more people live in certain area the greater scope there is for people to specialize in tasks and divide labor. This in one aspect self-explanatory since clearly when you have more people you can subdivide their tasks more but there.
In turn division of labor is extremely economically beneficial and allows us to increase production and consequently our material standards of living (as already observed by Adam Smith in the Wealth Of Nations). This drives people to aggregate in cities since thanks to specialization they can enjoy greater standards of living.
Economies of scale: Some production processes exhibit economies of scale - meaning the more you produce the more efficiently you can produce. This is technically connected to the division of labor mentioned above (Brueckner puts division of labor and economics of scale under one sub-chapter), but the division of labor is not exclusive cause of economics of scale and it also enhances production on its own so I thought they both deserve their own point.
Pecuniary agglomeration economies: "Pecuniary agglomeration economies lead to a reduction in the cost of a firm ' s inputs without affecting the productivity of the inputs" (Brueckner 2011). This is best explained by an example. Let us assume that firm needs to hire person with some rare combination of skills and let us assume only $0.5\%$ of population has such skill. Well then in a village of 100 people you would on average expect less than one such person to exist, in town of 10,000 people you would expect 50 such people, in city with 10,000,000 you would expect 50000 of such people. Hence, it would be easier to gather the special workers you need in large city than search across many small villages.
In addition when it comes to business to business (b2b) there will be higher competition among suppliers in big cities rather than small villages. Erosion of market power of suppliers reduces costs of businesses further down supply chain. There are other examples of these effects in the above mentioned book.
Technological agglomeration economies: "Technological agglomeration economies arise when a firm’s inputs are
more productive if it locates in a big city, amid a large concentration of
employment, than if it locates in a small city" (Brueckner 2011). This is because for example, in R&D there might be technological spillovers between firms.
Transport Costs and Firm Location: Transportation costs are obviously lower in places with high population density then when population is spread very thinly. It is also more efficient for similar firm to cluster together (e.g. silicon valley, Detroit's now infamous car manufacturing).
Retail Agglomeration: Cities historically originated around some important market and generally you will even nowadays find big shopping centers in cities not small villages. This reduces consumer costs and also their prices as there is more competition/they can do comparison shopping etc.
Geography: This one is not given significant treatment in Brueckner, but some sources consider it important (Fujita, 2002; Krugman, 1991). Earth surface is not homogenous. Some places might have excellent harbor, be at an important trade route and so on.
There might be also some other reason in the literature, my specialization is not Urban Economics so I do not purport to know the whole corpus of this body of research, but these seem to be the major reasons given by urban economics that are widely accepted.