Why were the shops of merchants initially close to the castle?

for the resources
for trade
for the population
for protection