Hadrian's Wall was the border between Roman Britain and Pict Britain. While it was not ever the border between England and Scotland, it did come extremely close to the modern border in the west. While this is very oversimplified, there are lines that can be drawn between Roman Britain becoming England and Pict Britan becoming Scotland. Why did the wall not form the border? How did this area north of the wall come to be English and not Scottish?
The short answer is war.
The slightly longer answer is that the wall was a non-factor in the Middle Ages, being totally ruined and of no military value. England and Scotland fought border wars for hundreds of years, and areas went back and forth between them until the border ultimately became settled after the Act of Union in 1707.
An example may be useful. The town of Berwick-upon-Tweed was founded by the Anglo-Saxon kingdom of Bernicia in the 10th century, which then became the Earldom of Northumbria when Wessex created the unified kingdom of England. Malcolm of Scotland captured the town and surrounding area in 1018. Henry II of England received it as part of the treaty signed after the 1173-1174 war with Scotland. Richard I then sold it back to Scotland in 1189. It remained in Scottish hands until Edward I captured it in 1296. The Scots recaptured it in 1318, but lost it again in 1333. It went back to Scotland in 1461, but the English captured it in 1482 and have controlled it ever since.
Dovetailing with u/Rittermeister's answer for the medieval border, there's an important point to make about the *Roman* border - namely, that Hadrian's Wall didn't form the border of Roman Britain. It's a common misconception but one that fundamentally misunderstands the nature of Roman frontiers.
Firstly, there isn't a contemporary Roman account that explains why Hadrian's Wall was built. The closest we have is a tentatively-restored stone inscription from Jarrow around AD 118, which vaguely links its construction to 'divine instruction'. The much-quoted line about it being built ' to separate the Romans from the barbarians' comes from the Historia Augusta, which is (put mildly) a problematic source. To summarise a lot of historical debate, it's almost certainly fourth century (so nowhere near a primary source) and almost certainly, for the most part, complete fiction. It's a nice source to show us how narratives of the past were used towards the agendas of fourth-century politics, but worse than useless for anything about Hadrian.^(1)
In his book on Roman frontiers, Hugh Elton asks the question of why troops were stationed on the frontiers in the first place, pointing out that this was a costly business - not least because it gave governors and commanders a readily-available supply of men to revolt against the imperial power, as many did throughout the imperial period. He looks at inscriptions and papyrus records from various frontiers, including in Asia Minor, on the Rhine and Danube, and in Egypt, and concludes that resisting invasions was a relatively minor part of their duties - most of what they did, and certainly most of what they claimed their mission to be, was suppressing banditry and cattle thievery, with no real distinction made as to whether those raiders came from inside or outside Roman territory.^(2)
This should clue us in to an obvious problem the 'wall as boundary line' idea - if the main point of having all these (expensive, politically risky) soldiers there was to protect an area from brigandage, it doesn't make sense to put them all on the far extreme of the area you're trying to protect. Moreover, the military logic doesn't make sense - the wall occupied between 10,000 and 25,000 Roman soldiers at various points, while the population of Caledonia has a rough upper bound at 100,000.^(3) This seems like a massive military overcommitment - a bit like the United States posting 50 million soldiers on the Mexican border. While there's a chicken-and-egg argument to be had here, it's also worth noting that this wasn't even a particularly hostile frontier - there are no records of major military incursions across Hadrian's Wall, except by the Romans themselves, between the conquest and the empire-wide crisis of the third century AD.
If you look at the wall itself, it's not very well designed, if defence was the main priority. The photogenic stone fortifications are only really a feature in the centre - about a third, on both ends but particularly in the west, was only ever built of turf and timber. The line of the wall often takes paths that miss out topographically prominent places in favour of areas that create 'dead ground' to the north, where any attack force couldn't be seen or effectively counteracted. Patricia Southern recounts a seminar at the University of Newcastle, where officers and soldiers from 'a modern military' unit toured the wall and commented that it wouldn't be defensible either from on top of it or from behind it - and the Romans knew what they were doing when it came to serious defensive architecture.^(4) Even had they wanted to, the manning and general 'combat readiness' of the troops on Hadrian's Wall seems to have often been pretty questionable. More fundamentally, though - if you want to build a wall to keep one group of people in and another group of people out, you don't put a gate every mile, and that's exactly what the builders did.
One of the key recent-ish developments in understanding Roman frontiers is that they weren't simple, binary lines. Rather, they were deep, fuzzy, overlapping military, economic, legal and cultural zones, where the directness and nature of Roman influence slowly changed. This is not a post-Westphalian world when countries can make maps and draw de jure borders on them - with very few exceptions, there was no such thing, and it's important to note that Roman ideology, at least in theory, never recognised the concept of a limit to Roman authority. The indispensable study here is C.R. Whittaker's 1994 Frontiers of the Roman Empire: A Social and Economic Study. He argues that frontiers were rarely static and were almost always permeable.^(5) Goods and people travelled across them constantly, not least to join the Roman army, and distributing prestige artefacts to 'barbarian' leaders was a major way that the Romans ensured their goodwill. The wall starts to make more sense within this context - in large part as a device to observe, control and perhaps tax this sort of movement.
One of Whittaker's major innovations is to look at the physical devices often held to constitute frontiers - particularly rivers such as the Rhine and Danube - and point out that they generally had to exist towards the back of this frontier zone. The main advantage of having a river is that you can move things along it - trade in good times but also soldiers and supplies in violent ones - and it's therefore important that the territory you directly control includes both banks, and a bit of a buffer zone in front. The same is true of Hadrian's Wall. In many respects, its key feature isn't the wall at all - the road, the 'Military Way', that runs parallel to it to the south. Fundamentally, what we're looking at here is a logistical structure, reasonably deep within Roman territory, that can be used to pool and move around men and supplies for a range of functions, of which fighting invaders was relatively low down the list of priorities.
Another good, recent book turning modern methodologies to Roman Britain is David Mattingly's 2012 An Imperial Possession: Britain in the Roman Empire. Mattingly devotes a lot of time to the role of the Roman army, and sees the main function of the troops on Hadrian's Walls as 'to supervise barbarian communities on both sides of the frontier'. In particular, he is concerned with economic exploitation, and discusses 'censuses' carried out of British peoples far into what we would call southern Scotland as a means to determine the amount that they 'owed' the Romans in tribute and military conscription. This fits the general picture we see of constant military movements by the Romans north of Hadrian's Wall, including the construction of reasonably durable fortifications, and again helps to demonstrate that the Romans never saw the wall as marking the northern limit of their empire.
Notes and Sources
As I've mentioned in the text - if you want to understand Roman frontiers, as well as the interesting historiographical story of why they've been so badly misinterpreted for so long, begin with CR Whittaker (1994) Frontiers of the Roman Empire: A Social and Economic Study. Mattingly's An Imperial Possession is also well worth a read, though is generally much more concerned about the social changes brought on by the Roman conquest: most of his treatment of the Roman Army is to look at it as a minority group within Roman Britain, with its own distinctive culture.
^(1) A decent recent survey of what the HA is and how it can be used is David Rohrbacher (2013) 'The Sources of the Historia Augusta Re-Examined', Histos 7, p.146-180 - though he's more charitable than me, and suggests that at least some of the material on Hadrian and other early emperors may have been based on a reasonably solid source.
^(2) In his book Frontiers of the Roman Empire (1996), p60-63.
^(3) This needs the standard disclaimer that population estimates for the ancient world are always very uncertain - this is the best I can find, from Lloyd Lang's 2006 The Archaeology of Celtic Britain and Ireland, c.AD 400-AD 1200, p21. Even if we only use it to within an order of magnitude, though, it gets the point across.
^(4) That is, Patricia Southern (2016) Hadrian's Wall: Everyday Life on a Roman Frontier. I'd like to find a direct source and in particular a date for that seminar (the fact that she mentions 'officers and soldiers', as well as the currently-fashionable interdisciplinary flavour, makes me suspect that it's vaguely post-Cold War), but haven't been able to.
^(5) The big exception here is that between the Roman empire and its Persian neighbours in the east, which was heavily militarised, often violent and much closer to a 'defensive line' - I'm not an expert on this area, but see e.g. Benjamin Isaac (1992) The Limits of Empire: The Roman Army in the East. However, much of the scholarship here still emphasises watching and monitoring movement across the frontier rather than any attempts, at least in peacetime, to prevent it.