Question: How did James III of Scotland acquire the town of Kirkwall?

Context paragraphs:
Tankerness: Tankerness is a district in the St Andrews parish in Mainland, Orkney, Scotland.  Essentially a peninsula, it is about 13 km south-east of Kirkwall and 1 km east of Kirkwall Airport.  The origin of the place name is uncertain, but it may derive from the Norse personal name "Tannskári".  A "ness" is a promontory.

James Aitken (bishop): James Aitken (died 1687) was a 17th-century Scottish prelate.  Born in either 1612 or 1613 in Kirkwall, Orkney, he was the son of Elizabeth "née" Buchanan and sometime sheriff of Orkney and Shetland, Henry Aitken.  After his school days at Kirkwall grammar school, he attended the University of Edinburgh, graduating on 23 July 1636, with an MA.  Subsequently, he travelled to England to study divinity at the University of Oxford.  Returning to Scotland as the chaplain of James, Marquess of Hamilton, he was given charge of the churches of Harray and Birsay on 27 June 1641.

Kirkwall Ba game: The Kirkwall Ba Game (also spelled ba') is one of the main annual events held in the town of Kirkwall, in Orkney, Scotland.  It is one of a number of Ba Games played in the streets of towns around Scotland; these are examples of games which are still played in towns in the United Kingdom and worldwide.  Games are played twice a year, normally on Christmas Day and New Year's Day.

Bishop's Palace, Kirkwall: The Bishop's Palace, Kirkwall is a 12th-century palace built at the same time as the adjacent St Magnus Cathedral in the centre of Kirkwall, Orkney, Scotland.  It housed the cathedral's first bishop, William the Old of the Norwegian Catholic church who took his authority from the Archbishop of Nidaros (Trondheim).  The ruined structure now looks like a small castle.

James III of Scotland: James III (10 July 1451/May 1452 – 11 June 1488) was King of Scots from 1460 to 1488.  James was an unpopular and ineffective monarch owing to an unwillingness to administer justice fairly, a policy of pursuing alliance with the Kingdom of England, and a disastrous relationship with nearly all his extended family.  However, it was through his marriage to Margaret of Denmark that the Orkney and Shetland islands became Scottish.

St Ola: St Ola is a parish in Mainland, Orkney.  It is in the centre of the island, east of the parish Firth and north of Holm.  It contains the capital and largest town of the Orkney archipelago, Kirkwall.  Both Kirkwall (Old Norse: "kirkjuvagr" , church-bay) and St Ola may take their name from the church of St. Olaf, built about 1035 on the north bank of the Willow burn, which stands just below the local primary school.

St Magnus Cathedral: St. Magnus Cathedral, Kirkwall dominates the skyline of Kirkwall, the main town of Orkney, a group of islands off the north coast of mainland Scotland.  It is the most northerly cathedral in Britain, a fine example of Romanesque architecture built for the bishops of Orkney when the islands were ruled by the Norse Earls of Orkney.  It is owned not by the church, but by the burgh of Kirkwall as a result of an act of King James III of Scotland following Orkney's annexation by the Scottish Crown in 1468.  It has its own dungeon.

Kirkwall: Kirkwall is the largest town and capital of the Orkney Islands of Scotland.  The town is first mentioned in "Orkneyinga saga" in the year 1046 when it is recorded as the residence of Rögnvald Brusason the Earl of Orkney, who was killed by his uncle Thorfinn the Mighty.  In 1486, King James III of Scotland elevated Kirkwall to the status of a royal burgh; modern roadsigns still indicate "The City and Royal Burgh of Kirkwall".

Kirkwall Castle: Kirkwall Castle, also known as King's Castle, was located in Kirkwall, the main settlement in the Orkney Islands of Scotland.  Built in the 14th century, it was deliberately destroyed in 1614.  The last ruins were cleared in the 19th century.  The castle was located around the corner of Broad Street and Castle Street in the centre of Kirkwall.

Kirkwall Airport: Kirkwall Airport (IATA: KOI, ICAO: EGPA) is the main airport serving Orkney in Scotland.  It is located 2.5 NM southeast of Kirkwall and is owned by Highlands and Islands Airports Limited.  The airport is used by Loganair & Flybe using its Franchise partner Eastern Airways.

Supporting paragraphs: Kirkwall James III of Scotland
Answer: marriage to Margaret of Denmark