The Trump administration's diversion of military funds to construct additional barriers to the United States-Mexico border wall was "unlawful," ruled a federal appeals court on Friday or three days after President Donald Trump visited a section of the wall in Arizona.

The $2.5 billion from the Pentagon was redirected to build 130 miles of barriers in California, Arizona, and New Mexico. In the 2-1 ruling, 9th U.S. Circuit Court of Appeals panel found that the administration defied the Congress' constitutional authority over federal funds.

"The Executive Branch lacked independent constitutional authority to authorize the transfer of funds," the ruling said. "The transfer of funds violated the Appropriations Clause, and, therefore, was unlawful."

The court sided with environmental groups that filed the lawsuit. However, a Supreme Court ruling issued last year stay, which allows the funds to be used and remains in effect for the time being, a report from CNN said.

In a report by The New York Times, Dror Ladin, a staff lawyer at the American Civil Liberties Union's National Security Project, said the 9th Circuit decision would help their argument before the Supreme Court, calling it "a win for the rule of law."

"There's no undoing the damage that's been done, but we will be back before the Supreme Court to finally put a stop to this destructive wall," said Ladin, pointing out the destruction of wildlife and desecration of cultural sites that has been brought by the construction of the border wall.

For his part, California Attorney General Xavier Becerra praised the court ruling. "We applaud the court for taking action to immediately halt Trump's unlawful money grab," he said in a report from NBC News

The administration took hold of the military fund last year after Congress refused to allocate money for the wall. A national emergency at the border was declared by Trump in order to access the money.

Haywood S. Gilliam Jr., U.S. district court judge, found that the administration could not prove "unforeseen military requirements" were needed to receive the money. The 9th Circuit agreed, noting that problems at the border wall, like drug smuggling, is not "unexpected."

The majority judges, Sidney Thomas and Kim McLane Wardlaw, were nominated to the court by former president Bill Clinton, while the dissenting judge Daniel Collins is a Trump appointee.

Collins said the filing parties, Sierra Club and the Southern Border Communities Coalition, did not have sufficient justification to stop the transfer of military funds. He wrote in his dissent that the administration has the authority to use the money for the border wall.

"By building fencing to stop international drug smuggling, the acting secretary of defense did not have to give even the slightest consideration to whether that reprogramming of funds would disrupt views of the desert landscape or affect local flora and fauna," Collins wrote, referring to the Department of Homeland Security.

Trump has faced a number of legal challenges regarding his border wall and his attempt to get additional funding from other government agencies. With about $15 billion border wall funding, the administration has completed over 200 miles of the wall system.

"My administration has done more than any administration [in history] to secure our southern border. Our border has never been more secure," Trump said.