First of all, investment banks are awash in capital thanks to 14 years of ZIRP and massive profitability. They don't like keeping cash on hand, so that means they dole it out into investments, some of which will flop.
Second, banks are the primary creditor in these deals, meaning they get paid first. They don't do these deals without ensuring that the company has enough saleable assets to ensure they get their pound of flesh. Lots of companies have billions in pension-earmarked reserves they don't have to pay out on if they declare bankruptcy. Guess who gets first dibs on that cash.
Third, they can shift the risk by selling their interest in these companies to another party. They are not stuck with it forever.
Image you have a goose that lays golden eggs. You could just keep selling the eggs every year but somebody comes up to you and offers you 2 billion dollars now and the public market values your golden egg business at 1.5 billion dollars so it seems fair.
It turns out that if you kill the goose there's a cache of 3 billion dollars worth of eggs within it.
The goose is gone and everybody made money off of it's demise.
---
PE (not always) is effective at finding under-valued companies and ensuring that they record the value on the PE's books.
Because it sometimes works. But it also sometimes destroys the companies.
But the “works” here is to just make PE richer in the short term, not to actually improve the company in the long term. That short term thinking leads to many impractical decisions that have caused bankruptcies