Castles were defensive fortifications. They were built near rivers or other trade routes. Usually in a town but there would soon be a town there if there wasn't already. Edwards castles in Wales for instance were all built on the coast or large navigable rivers.