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.
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.