So, it looks to me like a couple of things explain this epic fuckfest.
1. Young voters turning out for Corbyn. 18-24s, and many among us slightly older millennials were attracted to Corbyn's 'idealism,' 'authenticity' and spending promises, and maybe were also galvanized to vote by shock at Brexit. We all knew something like this could happen, but predictions of high youth turnout had been wrong before.
2. Snowball effect. As Corbyn surged people who wrote him off for being useless started to see him a new light. I suspect this explains the Scottish result in particular but it happened across the country. In other words, some of his unpopularity was founded on looking like a loser, and when he didn't any longe he picked up more votes.
3. UKIP voters. The % of UKIP voters who would ditch the party for the Tories was overestimated, and a substantial number actually went back to Labour. For those who understand the motives of UKIP voters, and the attitudes of Corbyn, this looks very bizarre, but tribal affinity to Labour is still strong and these voters heard what they wanted to hear when Corbyn spoke about immigration and Brexit.
I suspect we'll find more labour voters made up their minds late, while the Tory vote was locked in early.
The Tories should be thanking Ruth Davidson MSP on bended knees too, because if we hadn't defeated the SNP in some of their traditional heartlands we could really be looking at the coalition of chaos right now. England actually voted for a Lab-SNP pact, or the strong possibility of one anyway. Very odd indeed.