To some degree, this is handled by unemployment insurance premiums.
Most unemployment offices, in addition to the direct unemployment benefits, have retraining programs that often last well beyond when the direct benefits expire.
For example, I started my masters' degree part-time when I was still working at my first job. 4 weeks later i got laid off.
I got the standard unemployment benefits (26 weeks I think???) but when those ran out, I was still eligible for New Jersey's tuition waiver program (free tuition at a state school with some limitations - you're last in priority when classes fill up pretty much but that wasn't a problem in an EE graduate program) for the entire remaining duration of my M.S. program.