U.S. District Judge David O. Carter ruled the case -- the first of several pending challenges to the federal Defense of Marriage Act -- must be refiled in federal court.
Carter said the suit had been improperly filed in state court before it was transferred to his jurisdiction. As a result, the judge said, he would not entertain arguments on its merits, at least not yet.
"There is no point for us to go down the line of decision-making and waste time," he said during the hearing in Santa Ana.
The case, brought on behalf of a gay Southern California couple, argues that the Defense of Marriage Act, or DOMA, violates the U.S. Constitution by discriminating against gay men and lesbians.
The 1996 law bars federal recognition of gay unions, including the granting of Social Security survivor payments and other government benefits to couples.
Six states have now legalized same-sex marriage, but the federal law still bars those couples from receiving the benefits.
Gay marriage supporters accused Obama of betraying them this summer, after U.S. Justice Department lawyers filed court papers in the lawsuit strenuously defending the federal law. As a candidate, Obama pledged to work for its repeal.
Following the outcry, the president issued a memorandum extending some benefits to federal employees with same-sex partners. held a White House reception commemorating the 40th anniversary of the birth of the modern gay rights movement, and otherwise sought to reassure restive gay leaders.
Last week, when Justice lawyers filed a new round of papers seeking to dismiss the California case, Obama issued a statement saying he still wants to get rid of the federal law, but the government has an obligation to defend the laws passed by Congress.
Richard Gilbert, the lawyer handling the case for the plaintiffs, said he would accept Carter's invitation to submit it again.
Gilbert said he took the suit to state court only after another federal judge refused to waive court fees for his clients, Arthur Smelt and Christopher Hammer. The Orange County couple are disabled and live on fixed incomes, he said.
Monday's action was the latest episode in a five-year legal losing streak for the couple. With Gilbert representing then, they first went to federal court to challenge both the federal law and California's refusal to grant them a marriage license in 2004.
A federal judge ruled against them, and in 2006 the 9th U.S. Circuit Court of Appeals did as well, saying marriage laws were a state matter and that Smelt and Hammer were ineligible to challenge the federal law because they were unmarried and hadn't tried to secure any federal spousal benefits.
The couple were among the 18,000 same-sex couples who got married in California last year, before voters amended the state constitution to ban gay marriage. They renewed their complaint after Proposition 8 passed in November.
"They keep trying to kill Smelt and Hammer, and it just won't go away," Gilbert said of the ongoing litigation.
Brian Raum, a lawyer for the Alliance Defense Fund, a Christian legal group that has joined the government in defending the federal marriage law, said Carter was right to dismiss the case on procedural grounds.
The federal government cannot be sued in state courts, Raum said.
Smelt and Hammer's lawsuit could be back in a federal court in a matter of months, when "ultimately it will come down to the merits," he said.
Earlier this year, a gay rights group in Massachusetts filed a lawsuit challenging the Defense of Marriage Act on constitutional grounds. and the state brought a separate case arguing that the law interferes with its right to establish its own marriage laws.
In 2004, Massachusetts became the first U.S. state to legalize same-sex marriages.