The idea of a market is very old. It is basically a way of trading that does not need a shop, but really no more than a place on the ground. So even people with very small means can trade in a market.
You cannot trade unless you meet people who are likely to want to buy or swap what you have on offer, so it makes sense to go to meet them at a place everyone can get to easily. It also makes sense to go to places where your chances of trading are high. This is why small places tucked away from normal roads do not have markets.
If you look at a market town on a map, you will find that it has many roads coming in to it. This is what makes it a good place to trade. Once you have a place to trade, you need a space to trade. It always made sense to have that right in the middle of a town. So as a result some places became market towns.
In the past people also went to much bigger markets. They were called fairs. There was no room for them in the centre of a town, so they were set up on the outskirts. You still find big shopping places on the outskirts, although today we call them shopping malls and superstores.