Yes teachers, administrators, and principals are in unions and are protected, but layoffs can still occur within union contracts. People can still get fired, (of course, it's a lot harder), but unions understand that in order for a business, (in this case--a school district), there will be layoffs and firings.
In most cases, the teachers get no severance package as a corporate employee would, and because of their little salary, there is minimal cushion following the layoffs.
Your comparison between the corporate world and the education does highlight differences, but you exaggerate the influence and power of the unions. Labor unions can lobby, but they can't singlehandedly dictate economics. Nor can they grow money on trees.