Commercial banks and investment banks lent vast sums—trillions of dollars—for housing purchases and consumer loans to borrowers ill-equipped to repay.