(CN) – A federal judge in California ruled Friday against the Trump administration in two different lawsuits over the use of $2.5 billion in military funding to build part of a southern border wall.

Last month, U.S. District Judge Haywood Gilliam from the U.S. District Court of the Northern District of California, approved a temporary injunction blocking the feds from building sections of the wall in California, New Mexico, Arizona and Texas. Friday’s rulings made the injunction permanent.

President Donald Trump declared a national emergency at the border in February after Congress failed to allocate funding to his border wall. Using the declaration, Trump planned to divert money from the military to begin construction of the wall.

Gilliam wrote that Trump’s diversion of military funding was an unlawful action that attempted to bypass the authority of Congress.

“Defendants’ position on these factors boils down to an argument that the Court should not enjoin conduct found to be unlawful because the ends justify the mean,” Gilliam wrote in the case brought by the states. “No case supports this principle.”

The first lawsuit was brought by California on behalf of 20 other states. The second lawsuit was filed by the American Civil Liberties Union on behalf of the Southern Border Communities Coalition and the Sierra Club.

In the second lawsuit, Gilliam said members of the environmental rights groups would “suffer irreparable harm” if the border wall construction was allowed to begin.

“Congress considered all of Defendants’ proffered needs for border barrier construction, weighed the public interest in such construction against Defendants’ request for taxpayer money, and struck what it considered to be the proper balance — in the public’s interest — by making available only $1.375 billion in funding, which was for certain border barrier construction not at issue here,” Gilliam wrote.

In a statement, Sierra Club attorney Gloria Smith said her group was celebrating the decisions.

“We’ve seen the damage that the ever-expanding border wall has inflicted on communities and the environment for decades,” Smith said in a statement published by the ACLU. “Walls divide neighborhoods, worsen dangerous flooding, destroy lands and wildlife, and waste resources that should instead be used on the infrastructure these communities truly need.”

California Attorney General Xavier Becerra, who led the states’ fight against the Trump administration, also celebrated the decisions.

“These rulings critically stop President Trump’s illegal money grab to divert $2.5 billion of unauthorized funding for his pet project,” California Attorney General Xavier Becerra said in a statement Friday evening. “All President Trump has succeeded in building is a constitutional crisis, threatening immediate harm to our state. President Trump said he didn’t have to do this and that he would be unsuccessful in court. Today we proved that statement true.”

The administration did not immediately issue a statement on the ruling but is expected to appeal.