The Union of the Parliaments came about after a turbulent century following the union of the crowns. The 17th C was turbulent for most of Europe, religious war, the Thirty Years war in Germany, and you had the Wars of the Islands in England, Wales, Scotland, and Ireland.
Very, very few if any castles in Scotland were build by the English to hold the territory. That was Wales and the Edwardian Ring of castles around the modern county of Gwynedd. They were build for the same reasons castles were built in England, or in France. Control of the territory by the local rulers.
Now lets head to the 17th C. The wars of the 1640s and `1650s were devastating for all parts of these islands, and are considered the most deadly wars any of these nations has been involved in in the last 1000 years. The political situation was also shaky even when it was a time of peace. James VI/I had been a relatively good politician, probably one of the best politicians to sit on the throne of either Scotland or England, and had succeeded in England a good politician in Elizabeth I. Charles I was not, he was probably one of the worst politicians to sit on said thrones. His personal rule in the 1630s was disastrous. The 1649 - 60 Republic was always weak being based on the personality of one man, and the succession there led to a weak ruler with Richard Cromwell as Lord Protector.
Charles II on restoration was a better politician than his father and helped by the country being tired. However, he did not have legitimate children. This is probably because Queen Catherine had been rendered sterile by bad medical procedures when she miscarried. So the succession went to his brother, James. James VII/II was Catholic, something the protestant establishment in England and Scotland did not like, a truly dire politician, but he was also a Stuart so dynastic loyalty trumped this in Scotland.
When he was overthrown and the throne was gifted to William of Orange as he was married to James' daughter Mary problems came to a head. In short William was head of state of three countries, England, Scotland, and the Netherlands. Each had different political needs, but the Netherlands were at war with France. Now, who is Scotland's oldest ally? France. It was still trading with France. William banned this, without allowing Scotland to trade with England or the American colonies. Hence the disaster of the Darien scheme. He died childless, and none of Anne's children survived to adulthood.
So succession issue. England wanted a protestant monarch so passed the law sending the crown to the House of Hannover. Scotland would have had the Stuarts back. Result? French forces north of the border. So Anne pushed for the union of the parliaments, bought about in part by bribes, famine, economic crash, and pure political need. Creating the name of Kingdom of Great Britain, the island Wales, Scotland, England, and Yorkshire sit on, distinguishing it from the French Duchy of Brittany, known at the time sometimes as 'Little Britain'. It was messy, it was not inevitable, and it was a result of 'if it could go wrong in the 17th C, it did, frequently'