If flying from Edinburgh I would say to have the last night in Glasgow, rather than York. If the rail line from York to Edinburgh had a problem, then there is no alternative. From Glasgow to Edinburgh there are 5 rail routes, and a very frequent 24 hour coach service which goes direct to EDI airport, so you always have an alternative.
Haltwhistle and Hexham are both on the same train and bus route from Newcastle to Carlisle, and both are on the Hadrian's wall bus routes (AD122 and 185). Haltwhistle is a small town and the geographical centre of Britain, and makes a lot of that. Hexham is much larger, with big supermarkets and an independently owned Movie Theatre with a pub on the ground floor. Very much personal choice. How long you allow there depends on what you want to do on the wall. If you just want to see the wall and visit one of the forts allow a day. If you want to go walking the wall or part of it on the central core stretch, and visit each or most of the big forts allow 2 or 3 nights.
The unlimited travel Hadrian's wall bus pass in 2022 cost £12.50 for 1 day or £25 for 3 days.
The Bus times to Keswick are Hexham depart 0826, Haltwhistle 0906, Carlisle a 1000, depart 1100 Keswick a 1215 depart 1230 (and hourly to 1930) Grasmere a 1300, Ambleside a 1315, Windermere a 1333, or Hexham 0941 (then hourly) Haltwhistle 1018 Carlisle a 1105, depart 1200 or 1600, Keswick a 1315 or 1720.
To get from the Lakes to Glasgow- Windermere d 0909, Ambleside 0929, Grasmere 0945, Keswick a 1014 (hourly), change bus depart 1020 and hourly, Penrith Rail Station a 1102 (this is not as tight as it looks as you can change in the southern suburbs of Keswick if the 555 is a bit late, the drivers are very helpful). There is a train from Penrith to Glasgow at least hourly which takes less than 90 minutes. There is also a 1030 connection to Carlisle from Keswick, arrive 1150, then the same trains but in Carlisle it's a walk between bus and rail stations, so Penrith is the better route.
There is also a bus direct from Windermere to Penrith via Ullswater at 0925 (then every 2 hours), arrive Penrith Rail Station 1109.
If you decide on York as your last stay, catch a bus to Carlisle as above, then the train over the scenic Settle Carlisle railway at 1340, Leeds arr 1605, very frequent trains to York.