They get very large fees for "securitizing the deal", or being the ones who turns a bunch of loans into something that can be traded. In the case of very complicated deals, it can be several percent for a transaction that is low-risk for the bank since they've already identified both sides of the trade.