Medieval abbeys typically had several grades of accommodation, and it’s likely that the guesthouse was a royal residence right from the start. After the Reformation, a new palace was created out of the guesthouse and the west range of the abbey. Dunfermline Palace became the personal residence of James VI’s queen, Anna of Denmark.
The future Charles I was born here in 1600, the last monarch to be born in Scotland. Royal interest in Dunfermline waned when James and Anna left for London in 1603, and the palace fell into disrepair.
Historic Environment Scotland
Dunfermline was a favourite residence of many Scottish monarchs. Documented history of royal residence there begins in the 11th century with Malcolm III who made it his capital. His seat was the nearby Malcolm’s Tower, a few hundred yards to the west of the later palace. In the medieval period David II and James I of Scotland were both born at Dunfermline. Dunfermline Palace is attached to the historic Dunfermline Abbey, occupying a site between the abbey and deep gorge to the south. It is connected to the former monastic residential quarters of the abbey via a gatehouse above a pend (or yett), one of Dunfermline’s medieval gates. The building therefore occupies what was originally the guest house of the abbey. However, its remains largely reflect the form in which the building was remodelled by James IV around 1500.
. . .
Charles I returned to Scotland in 1633 for his coronation but only made a brief visit to his place of birth. The last monarch to occupy the palace was Charles II who stayed at Dunfermline in 1650 just before the Battle of Pitreavie. Anne Halkett described meeting him there. Soon afterwards, during the Cromwellian occupation of Scotland, the building was abandoned and by 1708 it had been unroofed. All that remains of the palace today is the kitchen, its cellars, and the impressive south wall with a commanding prospect over the Firth of Forth to the south.