Last week, Brooklyn Federal Judge Nicholas Garaufis effectively ordered the immediate dismantlement of New York’s system of privately run, but state-licensed, group homes for the mentally ill.

That decision was a slam-dunk victory for activists — if not for the mentally ill themselves. The judge ordered the cash-strapped state to build 1,500 housing units in each of the next three years — almost exactly as the activists demanded.

And he blasted the state’s compromise plan as “patently inadequate.”

As we noted then, moving the mentally ill into situations with reduced supervision invites disaster: It’s why New York had a profound homeless crisis in the ’70s and ’80s.

Garaufis’ decision makes no real-world sense — but he could have had more of a vested interest in this case than most might suspect.

It turns out that his wife for 18 years has been an active board member of Fountain House, which describes its mission as “dedicated to the recovery of men and women with mental illness by providing opportunities for our members to live, work and learn” and “the ultimate elimination of stigma against those with mental illness.”

In short, it’s an activist group for the rights of the mentally ill.

And while the organization was not a party to the lawsuit, the relationship still constitutes a startling conflict of interest on the part of Judge Garaufis.

According to the attorney general’s office, which represented the state, Garaufis did raise his wife’s affiliation with lawyers for both sides back in 2006, when he first began to hear the case.

True, the state’s lawyers did not see grounds for a mandatory recusal, in which the judge would automatically disqualify himself from hearing the case.

But that’s only half the story. Formally challenging the judge to step aside over a question of possible unfairness is fraught with potential professional dangers for a lawyer — not only in the case at hand, but in future appearances before the same jurist.

So Garaufis continued to preside.

Frankly, it wasn’t enough for the judge simply to raise the issue. He should have understood that his wife’s active involvement with the group represented the appearance — if not the actuality — of a blatant conflict of interest.

He should have stepped aside — without waiting for the state’s lawyers to demand it.

As we noted earlier, the judge found wrongly on the merits — dangerously so.