A big part of the problem was the way that risk was priced into the CDOs. The money that flowed into the mortgage market came largely from investment funds purchasing loans from banks after they had been packaged into CDOs.
The idea of the CDOs was that a large number of obligations from a diverse set of markets would be packaged together, allowing the overall risk to be calculated statistically. This calculation has ended up being incorrect for several reasons:
1) The historical time window for the CDOs was too short to have included a significant retrenchment in home prices.
2) An implicit assumption was made that different housing markets would retrench at different times, spreading the risk over time.
3) Most importantly: Nobody took into account that the front-line lenders (eg banks) would change their behavior in writing loans. When banks held the loan, they were much more careful about who they lent to. When all they were doing was originating loans for resale as CDOs, their standards became much more lax.
The upshot is that arguably the problem is that there was insufficient regulation of the CDO marketplace to allow for enough transparency to correctly calculate risk. The collapse in CDO prices has been because of this lack of transparency--you have no way of knowing about the quality of the loans underlying a given CDO.