Banks have already been paid for mortgages

If banks sell mortgages to investors, via the securitisation industry, how were they ever bust?
Pension funds, insurance companies, hedge funds, etc, buy mortgages and pay banks the principal, plus a premium up front as a lump-sum payment.