To understand where a cathedral might be placed, it is important to understand the function and history of cathedrals.
Note that the history is likely to depend on many different factors, and be different for different places, and that (as noted on the Wikipedia page):
"... cathedrals did not become universal within the Western Catholic Church until the 12th century"
I shall confine my answer to cathedrals in England and Scotland.
In England and Scotland, archaeological investigations have shown that most cathedrals are build on the sites of earlier churches (most dating to the Anglo Saxon period, but some with earlier origins). Examples would be Canterbury, Durham, Glasgow, Rochester, and Winchester.
In general, the location of the cathedral was, therefore, determined by the location of the pre-existing church. The location of that church could also be determined by a number of factors, but was basically the gift of the Anglo Saxon king. By no means were all these churches located in towns.
Once a church was built, settlements would tend to accrue around them. A church built at the edge of a settlement might find itself near the centre as the settlement expanded around it.
In the aftermath of the Norman Conquest of England, the new Archbishop of Canterbury, Lanfranc, presided over the Council of London in 1075 which ordered a significant restructuring of cathedrals in England:
By the decrees of Popes Damasus and Leo, and by the Councils of Sardica and Laodicea, whereby it is forbidden that bishops' sees should be in vills it was to towns, granted by royal favour and the Council's authority to the aforesaid three bishops to migrate from vills to cities - Hermann from Sherborne to Old Sarum, Stigand from Selsey to Chichester, Peter from Lichfield to Chester.
By Papal decree, cathedrals could no longer be located in vills. What this meant in 1075 was that Stigand, Bishop of the south Saxons, had to move his see from Selsey to Chichester; Hermann the Bishop of Wiltshire and Dorset had to move his see from Sherborne to Salisbury and Peter, the Bishop of Mercia, had to move his see from Lichfield to Chester.
This provided an obvious and immediate incentive for the expansion of the new cathedral churches in those cities!
The new Chichester Cathedral was consecrated in 1108.
Salisbury Cathedral was re-built on land donated by Richard Poore. The foundation stone was laid on 28 April 1220.
The See of the Bishop of Mercia was located in the Church of St John the Baptist in Chester from 1075 to 1082. In 1082 the see was moved to Coventry where it remained until finally being moved to Lichfield Cathedral in 1539. (The present Chester Cathedral was previously the abbey church of a Benedictine monastery established on that site in 1093.)
As noted above, Saxon kings granted land to establish the church and its precincts. This was rarely the 'best', or most-suitable land for building a large cathedral! Early churches were fairly small buildings. Some may have been relatively large in comparison to other buildings around them, but nothing like the scale of the cathedral buildings we see today!
The locations often caused significant problems for the medieval cathedral-builders (not to mention the problems the locations continue to cause for their modern counterparts, the cathedral conservators - whose job it is to try and prevent these buildings from falling down!).
About half of the cathedrals in England were ruled by monastic orders. The Prior of the monastery was also the Dean of the cathedral. The rest were run by secular canons, each headed by a secular Dean.
As you might expect, who was to be in charge of the cathedral was a significant factor in determining its location (and history). Monasteries accrued huge amounts of land in bequests throughout the medieval period, and how that land was used was determined by the monasteries themselves.
The Wikipedia article Historical development of Church of England dioceses has more information that you might find of interest in that regard.
Almost all cathedrals were extended and expanded following the Norman Conquest. In addition to making the church building itself bigger, that also often meant expanding the cathedral precinct. This, in turn, involved removing the people who had the misfortune to be in the way.
A notable feature of post-conquest urban architecture in England is that strategic locations, like The Hill, were often appropriated for The Castle. They were thus rarely available for building cathedral churches!
You'll find the subject has been covered in detail in the 2011 doctoral thesis The Old in the New: Urban Castle Imposition in Anglo-Norman England, AD1050-1150 by Michael Fradley.
Finally, the cathedral was the seat of the Bishop. However, that does not mean that it was also his primary residence.
From the Norman Conquest of England, many - perhaps most - bishops maintained sizeable and lavish palaces. These Bishop's palaces were often located outside their diocese. A notable example here is the palace in Southwark, on the south bank of the river Thames opposite the City of London, which was maintained by the Bishops of Winchester from about the mid twelfth century.
- Image source Wikimedia, Photograph by Mike Peel, CC-BY-SA-4.0.