As in, they would have to prove, potentially in court, that the layoff was absolutely necessary to actually be about to do it, plus pay an undefined fair severance amount (that people mostly seem to accept as 0.5 * monthly salary * years of tenure at the company), on top of the on-average 3 month notice period, which most companies will give as garden leave in order to not reduce morale even further.
If you can't prove that you need to cut the person for "operational" reasons (e.g. because you're not really getting rid of python tooling engineers), then your best bet is to dangle large cash offers to people in order to entice them to quit.
If they do manage to prove they need to do layoffs, for example when the company is literally running out of money, then they're not allowed to just lay off employees as they like (and definitely not in relation to performance). Instead they have to follow the "Sozialauswahl" which means that factors like whether the employee is supporting a family, is older, etc need to be taken into account.
Then on top of all that, they won't be able to hire people even for completely unrelated roles, for some amount of time afterwards.
So all in all there's a few disincentives for layoffs to be considered as a first action (it's not stopped it from happening at a bunch of companies lately though, Bosch, SoundCloud, Ableton, Native Instruments, Personio, Pitch etc).
I'm sure this comes with some drawbacks, perhaps more cautious hiring, but I like the sound of these regulations. Anything to give employees a ballast against wild swings in the share price. If layoffs had a more delayed effect on the business (and could be reversed in court) there would be less incentive for CEOs to pull that lever.
Aside from the mandatory negotiation with the employee co-determination (works council), the layoffs "must be determined according to the principles of social selection [...] (t)his is often perceived as a major obstacle [...] it would be disastrous to have to dismiss top performers simply because they are younger than other employees or have been recently hired."
You are on the spot, it's almost impossible to lay somebody off who is like 50 y/o and has kids + has been with the company for quite a while.
Generally, workers rights here in Germany are quite good so as an employee life tends to be quite comfortable since you don't have to fear termination the moment the company isn't doing exceptionally well.