The United Kingdom of Great Britain only dates from 1707.
But going further back:
Prior to the formation of Scotland and England as nations, the areas to become Scotland and England had different settlement patterns. Mainland Scotland's indigenous population were Brythonic Celts known as Picts who spoke a Celtic language related to Welsh. In the South West of Scotland, Irish Celts (known as the Scotti) began settling and spreading up the west coast. Through decades of conflict, trade and intermarriage, the two groups coalesced until the first King of Scots, Kenneth MacAlpine, of both Pictish and Scotti ancestry ascended to the throne.
England was largely settled by Germanic tribes, the Anglo-Saxons from Frisia, Schleswig and Jutland; pushing England's Brythonic Celts west into Wales and Cornwall. England was ruled by a number of small Saxon Kingdoms, who's influence and language were spreading into southern Scotland.
Circa 900AD, England and Scotland are linguistically and ethnically different places.
The next wave of settlement follows: Norwegian Vikings settle in the North West of Scotland and in Orkney and Shetland whilst Danish Vikings settle and control large areas of Northern England, in an area known as the Danelaw. The Saxon Kingdoms have coalesced into a single Kingdom by this point, and there is continued friction between the Danes and Saxons.
In 1066, the Saxons inflict a decisive defeat on the Danes at the Battle of Stamford Bridge.
Shortly after, Normans - descendents of Vikings living in Northern France and speaking a Romantic language invade England and defeat the Saxons at the Battle of Hastings.
The Normans raid northern England and push towards Scotland, but do not invade. In order to maintain Scotland as an.independent Kingdom, Norman landowners are invited to settle in Scotland as feudal landlords and form the new Scottish aristocracy.
In the late 1200s, Edward I attempts to expand English rule into Scotland. This is a complicated period of Scots history, with many betrayals, shifting loyalties, bloody battles, but the end result is that English are comprehensively defeated by a much smaller Scottish army at the Battle of Bannockburn in 1314 - an event that still has great resonance with many Scots today. In 1320, the declaration of Arbroath is written: an appeal to the Pope to provide legal support for Scottish nationhood which is successful.
Scotland and England remain independent nations, sometimes at peace, sometimes at war until the early 1600s, when James VI of Scotland ascends to both thrones. As both countries were Protestant, this causes less conflict than when Mary Queen of Scots, a Catholic, was high in Protestant England's order of succession.
The next 100 years goes a bit mad, wars, rebellions and a bit of ethnic cleansing all over, normally called the English Civil War, but not limited to England. In the economic boom that follows peace, many of Scotland's Upper Class invested vast amounts of.money in an attempt to set up a trading colony in Darken, the portage route between the Pacific and Atlantic Oceans. The venture fails, and Scotland's nobility are left bankrupt. England seizes the opportunity to permanently secure their northern border, and the Scottish nobles are bribed into dissolving their parliament and sitting in the English parliament as the two nations are merged to form the United Kingdom of Great Britain.
I've missed a vast amount out, and barely touched on the motivations of the people involved.
I've also not mentioned Ireland, which always looms large in British history.
Summary: Q - Why are Scotland and Wales different countries to England? A - Each nation was settled by different cultures during their formation.
Q - Why isn't it all just England? A - The English tried. The English failed.
Q - How did Britain come about? A - The parliaments of each nation voted to merge in 1707 to secure England's northern border and to guarantee a Protestant succession.