This is a story that will be different for each of the countries you ask about, but I will answer for Scotland, and specifically for Gaelic (because the various forms of Scots have a different, but intertwined, history I am not familiar enough with).
First of all, you should understand that Gaelic was never the singular language of what would become Scotland, though it did extend over a far larger area than is usually understood. It likely arrived from Ireland and expanded westward from Argyll. It was once a language of the kings of Scotland. It reached its greatest extent with the MacDonalds Lords of the Isles, which originated from lands granted to Aonghus Og MacDhòmhaill for his services to Robert the Bruce before the Bruce took power. (For anyone who watched Outlaw King this is who the random unnamed red-haired guy who hangs around the whole movie is.)
Anyway, the MacDonalds Lords of the Isles were related to MacDonald lords in Ireland, and there was a considerable exchange of knowledge and culture during this period. However, the Lordship eventually was forfeit to the Scottish crown (and I'm eliding a lot here because it's not really relevant here). In 1609, the Statutes of Iona were passed which, among other things, required that the eldest sons of each chiefly household be educated in English. This was passed by James IV, who in addition to being the king to subdue the Lordship, was also the first monarch of Scotland who did not speak Gaelic.
The Statues are often held to be the first piece of anti-Gaelic legislation passed, but it is important to also note that Gaelic was already on a bit of a decline. While the Irish centres of learning held immense knowledge, by the medieval period, learned kindred such as the Beaton medical family were beginning to travel to Europe to seek out learning and adventure. Gaelic did not serve as well as Latin, and many of the medical treatises are in Latin rather than Gaelic even during the classical period.
The Statutes of Iona did not immediately sever linguistic ties to the Highlands (i.e. Gaelic) in the gentry, but did serve to introduce them to more luxurious and expensive standards of living to aspire to, helping to separate them from the other Gaelic-speaking clansmen. This slow alienation helped to drive the shift from chief to landlord, which also carried with it a further identification with English culture and wealth.
By the 18th century, some chiefs had already lost their Gaelic. John Campbell of Mamore, 4th Duke of Argyll, was likely the first of his family not to speak English as he had been raised in the South. The MacDonalds carried knowledge longer, though it was very rare for any to be able to write it (it is noted in the Lyon in Mourning that only Clanranald and Alasdair Mac Mhaighstir Alasdair among the MacDonalds were still able to write "erse" in its ancient script).
Gaelic, then, was already in retreat by the time of the Jacobite defeat at Culloden. The language was widely disparaged, and with hereditary chiefs now operating wholly as landlords, a class divide emerged as well in terms of who spoke it and who did not. The end of the Lordship hundreds of years earlier had broken scholarly ties with Ireland, and most Gaelic speakers were not able to write down their language.
Post-Culloden, the Act of Proscription did not actually ban Gaelic. However, the transformation of the chieftainry into landlords had side effects, notably debt. Many schemes were tried to pay off debt, the most notorious being the simple, if callous, expedient of replacing expensive people with sheep. This had the effect of driving Gaelic-speaking people off their landholdings and into lowland Scottish cities or into poor quality crofting lands to farm seaweed (then a lucrative job). Others, veteran soldiers, joined the army as loyal servants of the Crown (even if a fair few had been rebels not long before) and travelled overseas to fight in territorial wars. In North America, they received land under the Royal Proclamation of 1763 in proportion to their rank. When they settled with their families, they carried their language out of the Highlands and into new settlements.
To sum up before I wander off topic, English came to dominate Gaelic Scotland as Gaelic ceased to be a language of the Scottish Kings, the Lordship of the Isles weakened and ultimately yielded, ties with classical Irish scholarship were broken, and the Statutes of Iona helped to severe chiefly ties to both the language and the people. Then, the Highland Clearances, crofting, and soldiery helped to carry Gaelic-speakers out of the highlands to new locations all around the world.