St Andrews Castle St Andrew ' s Castle is a picturesque ruin located in the coastal Royal Burgh of St Andrews in Fife , Scotland . The castle sits on a rocky promontory overlooking a small beach called Castle Sands and the adjoining North Sea . There has been a castle standing at the site since the times of Bishop Roger ( 1189 - 1202 ) , son of the Earl of Leicester . It housed the burgh ’ s wealthy and powerful bishops while St Andrews served as the ecclesiastical centre of Scotland during the years before the Protestant Reformation . In their Latin charters , the Archbishops of St Andrews wrote of the castle as their Palace , signing , " apud Palatium nostrum . " The castle ' s grounds are now maintained by Historic Scotland , and are entered through a visitor centre with displays on its history . Some of the best surviving carved fragments from the castle are displayed in the centre , which also has a shop . Wars of Scottish Independence . During the Wars of Scottish Independence , the castle was destroyed and rebuilt several times as it changed hands between the Scots and the English . Soon after the sack of Berwick in 1296 by Edward I of England , the castle was taken and made ready for the English king in 1303 . In 1314 , however , after the Scottish victory at Bannockburn , the castle was retaken and repaired by Bishop William Lamberton , Guardian of Scotland , a loyal supporter of King Robert the Bruce . The English had recaptured it again by the 1330s and reinforced its defences in 1336 , but to no avail . Sir Andrew Moray , Regent of Scotland in the absence of David II , recaptured it after a siege lasting three weeks . Shortly after this , in 1336 - 1337 , it was destroyed by the Scots to prevent the English from once again using it as a stronghold . It remained in this ruined state until Bishop Walter Trail rebuilt it at the turn of the century . His castle forms the basis of what can be seen today . He completed work on the castle in about 1400 and died within its walls in 1401 . Home to kings . Several notable figures spent time in the castle over the next several years . James I of Scotland ( 1406 - 1437 ) received part of his education from Bishop Henry Wardlaw , the founder of St Andrews University in 1410 . A later resident , Bishop James Kennedy , was a trusted advisor of James II of Scotland ( 1437 - 1460 ) . In 1445 the castle was the birthplace of James III of Scotland . Use as a prison . During these years , the castle also served as a notorious prison . The castle ' s “ bottle dungeon ” is a dank and airless pit cut out of solid rock below the north - west tower . It housed local miscreants who fell under the Bishop ' s jurisdiction as well as several more prominent individuals such as David Stuart , Duke of Rothesay in 1402 , Duke Murdoch in 1425 , and Archbishop Patrick Graham , who was judged to be insane and imprisoned in his own castle in 1478 . Reformation and siege . During the Scottish Reformation , the castle became a centre of religious persecution and controversy . Referring to the bottle dungeon the Scottish reformer , John Knox , wrote , " Many of God ' s Children were imprisoned here . " In 1521 James Beaton , then Archbishop of Glasgow , won the seat of St Andrews and took up residence in the castle . Beaton altered the defences to enable the castle to withstand a heavy artillery attack , which was a threat as tensions grew between English Protestants and Scottish Catholics . In 1538 James Beaton was succeeded by his ambitious and wealthy nephew David Beaton . Cardinal David Beaton ' s strong opposition to the marriage of Mary , Queen of Scots , with Prince Edward ( later King Edward VI ) , the son and heir of Henry VIII of England , helped to spark renewed fighting in 1544 . Scottish Protestants were increasingly viewed as dangerous turncoats who sided with the English . In 1546 David Beaton imprisoned the Protestant preacher George Wishart ( 1513 - 1546 ) in the castle ’ s Sea Tower and had him burnt at the stake in front of the castle walls on March 1 . Today , brick lettering with his initials marks the spot where he died . In May of that same year , Wishart ' s friends conspired against the cardinal . On May 26 they gained entry to the castle by disguising themselves as masons when some building work was in progress . After overcoming the garrison , they murdered Cardinal Beaton and hung his body from his window on the front of the castle . Following this murder , the Protestants took refuge in the castle and formed the first Protestant congregation in Scotland . A long siege was ordered by the Scottish Regent , James Hamilton , 2nd Earl of Arran . In October 1546 a mine was begun by the attackers which was successfully counter - mined by the defenders . Both the mine and counter - mine cut through solid rock . They were rediscovered in 1879 and remain open to the public today . Arran heard that an English army was on its way to relieve the Castle and asked Fife Lairds like John Wemyss of that Ilk to come by 4 November 1546 , bringing his followers and whatever artillery they had to resist a sea invasion . Although Henry VIII made plans to assist the Protestants within the castle , the invasion never came and his son Edward VI did not send aid . During an armistice in April 1547 , John Knox entered the castle and served as the garrison ' s preacher for the remainder of the siege . For a time Knox had the freedom to pass to and from the castle to preach in the parish church . This peaceful interlude came to end , however , when a French fleet arrived bringing an Italian engineer Leone Strozzi who directed a devastating artillery bombardment to dislodge the Protestant lairds . The lairds knew an expert was in the field when their own Italian engineer observed cannon being winched into position with ropes rather than exposing the besiegers to their fire . Guns were also placed on St Salvator ' s and the cathedral towers . One of the largest Scottish cannon was called " thrawynmouthe . " The castle was quickly rendered indefensible ; within six hours according to Robert Lindsay of Pitscottie . The defeated Protestants were taken away : some were imprisoned in France while others , including Knox , were condemned to the galley s . Decline and current condition . Following this Protestant defeat , the castle was substantially rebuilt by Archbishop John Hamilton , the illegitimate brother of Regent Arran , and successor to Dr . David Cardinal Beaton . But following his death in 1571 it was mainly occupied by a succession of constables . Parliament separated the castle from the archbishopric in 1606 , and it was granted to the Earl of Dunbar , constable since 1603 . In 1612 it was returned to Archbishop George Gledstanes , but further attempts to re - establish the former estates of the Archbishop failed . With the eventual success of the Reformation in Scotland , the office of the bishop was increasingly eroded until it was finally abolished by William of Orange in 1689 . Deprived of any function , the castle fell rapidly into ruin . By 1656 , it had fallen into such disrepair that the burgh council ordered the use of its materials in repairing the pier . The principal remains are a portion of the south wall enclosing a square tower , the " bottle dungeon , " the kitchen tower , and the underground mine and counter - mine . Footnotes .