Unions don’t prevent layoffs. You’re bound by a union contract which will include conditions for layoffs. Unions can prevent overwork and burn out. They cannot prevent layoffs.
Indeed, I think their major trick (in America, anyway) is to make a profitable company unprofitable. Much like the bad forms of private equity from above, they bleed a business dry from below.