Modern restaurants find their roots in eighteenth-century Paris. However, this depends on how you are defining restaurants - for the sake of this answer, a restaurant is a fine dining destination that has more to do with preference and luxury than convenience. The restaurant is a place where the customer can eat at their leisure and to suit their taste, food is a commodity rather than something which is functional.
We find examples of restaurant cultures in ancient Rome, and in Song dynasty China. In the case of Rome, some evidence we can find are in the ruins at Pompeii where just over 150 buildings have been identified which have counters facing the street, of which 128 have evidence of on-site cooking. Traces and residues left behind in containers and drains also suggest that more complicated meals were prepared here and served to sitting guests. Equally, traveller's accounts of China in the 11th and 12th centuries describe lavish teahouses and dining halls that provided entertainment alongside fine foods and drinks. These accounts also describe how different dining destinations had different specialities - in this way, they weren't just convenience stops.
The modern Western concept of a restaurant is connected to the growth of coffeehouses and cafes in the 17th and 18th centuries. In the 1760s and 1770s, certain locations in Paris served light foods to people in "delicate health" as a quasi-medicinal practice. The word restaurant is closely linked to the word for restoration. These then developed into more busy locations, and by the turn of the 19th century tourist accounts and guidebooks for Paris were full of praise for the new-fangled restaurant culture. Throughout the remainder of the 19th century, these ideas and practices spread around the Western world as a result of France's economic and social prestige.
It is important to consider that being able to eat out at a restaurant requires having access to disposable income, and choosing to spend this excess wealth on a one-off luxury experience. This means that there is a very close relationship between the expansion of the moneyed classes and the growth of restaurant culture. Naturally, the earliest clients of modern Parisian-style restaurants tended to be aristocratic or upper-class.
With time, restaurants began to diversify to accommodate the public's more varied preferences and to include people who might traditionally have been excluded from this 'high culture' practice. In one example, this might mean catering for working women as well as well-to-do socialites, or the gradual increase in the availability of convenience food (early 20th century) rather than the exclusivity of early restaurants.
Jumping forwards a little - after the difficult years of the Great Depression and the Second World War, restaurant culture expanded and developed again. This saw the gradual decline of France as the leading cultural influence on the 'shape' of restaurants, and a similar trend towards making the 'restaurant experience' more accessible to middle-class families. Traditional lavish restaurants were expensive, exclusive, and relied on highly specialised workers catering to wealthy patrons - this model simply did not work so well in a world where wealth was more widely distributed (both socially and geographically). By the end of the 1970s, it was reasonably commonplace to find restaurants which very closely resemble the experiences we have available to us today.
In short, restaurants weren't singularly invented at one point in time. Instead it's more like the idea of eating and socialising was continuously reinvented over a period of time and in line with other cultural-historical developments. However, we can pin this timeline to certain moments like the boom in cafe culture, the development of fine dining 'destinations', and the eventual spread of affordable franchises like McDonalds in the 1950s.
(This answer predominantly reflects European and North-American understandings of restaurants. When you're discussing a topic as broad as 'when did X originate' it's very rare that there will be a single linear process that was adhered to in sync by every culture around the world)
References: