Image copyright Getty Images Image caption Protests were held around the country when the order was first signed

The Trump administration has suffered twin legal defeats on its immigration and transgender policies.

A California judge permanently blocked a presidential order to cut funding from US cities that refuse to co-operate with immigration officials.

And a Maryland judge blocked the administration's ban on transgender people from serving in the military.

President Donald Trump's proposed travel ban has also been hit by courtroom setbacks.

California US District Judge William Orrick ruled that the immigration order was "unconstitutional on its face".

Media playback is unsupported on your device Media caption The church defying Trump by hiding immigrants facing deportation

He temporarily blocked the order back in April.

"The Constitution vests the spending powers in Congress, not the President, so the Executive Order cannot constitutionally place new conditions on federal funds," he wrote on Monday.

"Federal funding that bears no meaningful relationship to immigration enforcement cannot be threatened merely because a jurisdiction chooses an immigration enforcement strategy of which the President disapproves."

The executive order was issued just days after President Trump took office in January.

It sought to withhold funds from cities that would not co-operate with federal immigration requests to turn over any individual arrested for a crime and suspected of entering the US illegally.

Dozens of municipalities, including New York, Los Angeles and Chicago, have joined the so-called sanctuary movement.

San Francisco and Santa Clara County had sued, arguing they would lose billions of dollars in federal grant funding if the president was allowed to enforce the order.

Department of Justice spokesman Devin O'Malley said in a statement late on Monday that the 9th US Circuit Court of Appeals had "exceeded its authority today when it barred the President from instructing his cabinet members to enforce existing law".

Media playback is unsupported on your device Media caption Sanctuary cities under threat by Donald Trump

"The Justice Department will vindicate the President's lawful authority to direct the executive branch," he added.

The federal agency has already appealed against Judge Orrick's ruling in April.

San Francisco City Attorney Dennis Herrera called the ruling "a victory for the American people and the rule of law".

"No one is above the law, including the president. President Trump might be able to tweet whatever comes to mind, but he can't grant himself new authority because he feels like it," he said in a statement.

Mr Trump has yet to comment on the final ruling.

Over the summer when the order was temporarily blocked, he tweeted that it was "ridiculous".

The White House claimed at the time that the judge had given a "gift" to gangs that put "thousands of innocent lives at risk".

Chicago also sued the federal government in August over the Justice Department's threats to cut funding. A federal judge issued a preliminary injunction blocking the US government from withholding public-safety grants.

Meanwhile, in Baltimore on Tuesday, US District Judge Marvin Garbis delivered another blow to the Trump administration by blocking its ban on transgender people serving in the military.

Judge Garbis ruled that the policy "cannot possibly constitute a legitimate government interest".

His ruling echoes a previous one by a federal judge in Washington on 30 October.