Congress designed Fannie and Freddie to serve both their investors and the political class. Demanding that Fannie and Freddie do more to increase home ownership among poor people allowed Congress and the White House to subsidize low-income housing outside of the budget, at least in the short run. It was a political free lunch.
In 1968, President Johnson had Congress create the Government National Mortgage Association and sell Fannie Mae to private investors. The reason for these actions was exactly the same as the reason that Enron created Special Purpose Vehicles: to get liabilities off of the balance sheet and hide risk.
Before GNMA and while Fannie Mae was a government agency, the National Debt included all of the money borrowed to finance mortgages bought by Fannie or insured by the Federal Housing Administration (FHA) and under special programs for veterans and military families (VA). President Johnson was embarrassed to ask for increases in the ceiling on the national debt at the time when we were fighting an unpopular war in Vietnam. Moving government housing programs to off-balance-sheet entities served that purpose. GNMA sold pools of FHA and VA mortgages, reducing government borrowing. Spinning Fannie Mae off to private investors took Fannie's debt off the government books.
In 1970, Congress created Freddie Mac, and eventually spun it off as it had Fannie Mae. However, the separation of Freddie and Fannie from the government was never clearcut. They continued to serve as vehicles for implementing federal housing policy, as Roberts documents. Ultimately, as with Enron's SPV's, when things started to go sour it turned out that Fannie and Freddie had never really left the government's balance sheet.