HOUSING FINANCE giants Fannie Mae and Freddie Mac remain in institutional limbo, ruled by the Federal Housing Finance Agency (FHFA) until Congress finally agrees on a new housing finance system to replace the two entities, which went belly-up six years ago. The resulting uncertainty is bad for the housing market. Still, things could be worse — a bunch of opportunistic hedge funds could get a federal judge to hand them the now-profitable mortgage giants on a silver platter.

Fortunately, that deeply unfair outcome got much less likely on Tuesday when Judge Royce H. Lamberth of the U.S. District Court in Washington dismissed a lawsuit by Wall Street speculators who have been trying to convert their residual minority stakes in Fannie and Freddie into a multibillion-dollar windfall profit. In an epic bit of legal chutzpah, these private investors had tried to recast the Fannie-Freddie bailout — one of several federal emergency measures that might well have saved American free-market capitalism for the next generation — as an attack on their sacred property rights. The theory was that the value of their stock had been destroyed by a 2012 agreement between the Treasury Department and FHFA that commits all future Fannie-Freddie profits to the government — instead of to private shareholders like the hedge funds. Never mind that the funds mostly bought their shares for peanuts at post-bailout fire-sale prices, whereas the government — i.e., taxpayers — advanced the firms $187 billion before all was said and done.

In a crisply reasoned and trenchantly worded 52-page opinion, Judge Lamberth made short work of the hedge funds’ claim that Treasury and FHFA exceeded their statutory authority by agreeing to “sweep” future profits back to the government, in lieu of the previous bailout repayment scheme, which set a 10 percent dividend on the government’s 79.9 percent stake in the firms. To the contrary, the judge ruled, a close reading of the applicable law, which Congress adopted in 2008, shows that it not only grants regulators and Treasury near-total power over Fannie, Freddie and their respective cash flows, but also expressly denies federal courts nearly any jurisdiction to review those agencies’ actions. “The plaintiffs’ true gripe is with the language of a statute that enabled FHFA and, consequently, Treasury, to take unprecedented steps to salvage the largest players in the mortgage finance industry before their looming collapse triggered a systemic panic,” Judge Lamberth observed.

This is not the last word on the subject, both because the plaintiffs in this case may appeal and because similar lawsuits are pending in other courts. But as a plunge in Fannie and Freddie stock prices suggests, the hedge funds’ failure to persuade a respected veteran of the federal bench like Judge Lamberth is a decidedly bearish indicator for those who would go running to court in hopes of realizing a taxpayer-subsidized fortune. Now it’s up to Congress to finish the job, by passing a permanent fix to this country’s crippled housing finance system.