Let's work backwards. Wall St brokerage firms failed after it became impossible to sell their "mortgage backed securities" when they needed cash. The "mortgage backed securities" promised high yield with low risk, and the brokerage houses printed huge amounts of them and sold them to gullible investors and to Frannie and Freddie. They were so profitable that the brokerages became willing to buy sub prime and "liar's loan" mortgages, because turning them into "mortgage backed securities" was profitable.
Things came unglued in 2006 when the gullible investors discovered that the price of houses had dropped so much that the mortgages were worth more than the houses. All of a sudden the "mortgage backed" part of the securities began to look risky. The gullible investors wised up and stopped buying them. Leaving the brokerage houses with barrels of "securities" that no one would buy. "Illiquid" is the Wall St jargon for "so crummy no one will touch it".
Why did the price of houses fall in 2006? A better question is why did the price of houses rise the rapidly in the previous decade? Answer, the price of houses went up because the banks were willing do higher loans on the properties. Remember a mortgage is a simple deal, I loan you money, you pay it back or I take the house. This only works if the house is worth MORE than the mortgage. Successful banks are good at assessing property values and would not do mortgages that exceeded their idea of what the property was really worth.
But then, a horde of eager stock brokers descended upon the banks offering to buy the bank's mortgages for cash. So they could turn them into "mortgage backed securities". Such a deal. Once sold, the bank was free of risk, if the mortgage defaulted the gullible buyer had a problem, not the issuing bank. The bank gets to keep the closing fees, points, and perhaps a markup, and hustles out to do more mortgages.
Now that the bank can sell mortgages, it ceased to care that much about the quality of the mortgage. Do a low quality mortgage, offer to finance a little more than the property is worth, offer to waive the down payment. Sell the result before something goes wrong. Result, price of housing goes up, 'cause the bank is willing to loan more money on the same old property.
Why were the brokerage houses so willing to do mortgage backed securities? Simple, Fannie and Freddie were willing to buy enormous quantities of them. They had the money (borrowed on the credit of the United States) and the returns promised by the brokerage houses looked sooo good.
What's the moral of the story? Simple, shut down the entire secondary mortgage market, force the banks to risk their own depositor's money. To a large extent this has happened, the market for "mortgage backed securities" has dried up, no one will touch them any more. When the bank risks it's own money, it will be more careful. Just to make sure the secondary mortgage market stays closed, close down Fannie and Freddie for good.
And, remember that Barnie Frank and Chris Dodd defeated all attempts to limit Fannie and Freddie's borrowing power, leaving us taxpayers stuck with the horrendous losses they racked up.