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.
[Source] Random link from the Internet so that I don't need to translate: https://www.emplawyers-muenchen.de/wp-content/uploads/files/...