The banks made loans that they then immediately sold in the form of securitized mortgages, so they didn't care about whether or not the borrowers could really repay. It turns out the borrowers couldn't.
The banks, pension funds, etc., then re-bought the securities based on the mortgages. Woops. Woops.