To put it simply, most were simply no longer useful, or indeed were actively problematic. Not just in Scotland, but also in England and Wales, this typically came down to one of four reasons: The Reformation, the Civil War, changes in both warfare and housing fashions, or the Jacobite Rebellions. For two pertinent Scottish examples, we could look at Urquhart Castle on Loch Ness and Beauly Abbey near Inverness, and find an English comparisson in Corfe Castle in Dorset.
Urquhart Castle has a long and storied history, often as a frontline defence against Douglas raiders challenging the authority of Edinburgh. Over the centuries of its life, the occupation of the site moved from the original small keep on a hill overlooking Loch Ness to a more extensive series of halls and a tower keep in a more expansive bailey, which led to the original areas of the castle already falling into disuse by the fifteenth century. As with many castles across the British Isles, the relative peace and stability of the 16th Century led to a gradual move away traditional castles to what were essentially more luxurious fortified manor houses, a process that was curtailed abruptly, and then rapidly accelerated in England by the Civil War. Urquhart had been devastated by a raid of 1545 and been extensively rebuilt, but by 1647 was largely empty. By the time of the Jacobite Rebellion, Urquhart Castle had largely been rendered insignificant. Modern gunpowder weapons had significantly reduced the usefulness of its walls, and Loch Ness was now controlled by two much more modern fortifications built at either end by Oliver Cromwell's New Model Army in the 1650s. Nonetheless, the castle would have been an annoying obstacle if captured, and so required its pro-Hannoverian owners to leave a garrison behind to prevent it falling into Jacobite hands. While the garrison did indeed prevent the capture of the castle by a superior Jacobite force, the Castle was seen increasingly as an unwelcome expense. As with many castles, Urquhart was no longer a primary residence; the Grant family spent most of their time at their other estates, which, while less defensible, allowed for much larger, modern and comfortable homes, or further afield in Edinburgh or even London. As a result, this unwelcome expense was also deemed unnecessary, and the castle was largely demolished and abandoned in 1690.
An English comparisson is Corfe Castle: held by the Royalist Bankes family during the Civil War, the castle was seized by Parliamentarians and then heavily demolished with explosives as it was strategically useless to them apart from as an obstacle. Many other significant castles, such as Bristol and Wardour, suffered a similar fate as their strategic obselesence made their demolition more viable than their continued use. Post-Restoration, the Bankes family built their new home at nearby Kingston Lacy as a manor house - sufficiently modern fortification having become not only expensive but also politically and domestically unviable in the wake of the Civil War.
Beauly Abbey, near to Urquhart, suffered a similar fate to countless other abbeys, monasteries, convents and chapter houses across Britain: The Reformation. With the abolition and heavy censure of the Roman Catholic Church, vast numbers of Church estates were seized by the state in both England and Scotland. Some, like Lacock in Wiltshire, passed into private ownership and were repurposed as family houses while others, such as Temple Church in Bristol, became parish churches, but huge number were simply abandoned as their communities were abolished and their lands sold off to the highest bidder or snapped up by local landowners. Given that many religious houses had been purposefully established in remote locations, or had gradually acreted settlements which in turn had their own chapels, many of these abolished and abandoned institutions were simply allowed to rot, or even actively plundered as a cheap and ready source of pre-cut stonework for local construction. Beauly itself was abolished in 1634 and its estates given over to the Bishop of Ross. The Abbey remained in local use largely for its graveyard, and essentially became a giant mausoleum, falling slowly into disrepair.