A federal appeals court in New York granted the Trump administration permission to withhold millions of dollars in funding from New York City and seven "sanctuary" states that have refused to assist in transferring illegal immigrants from local law enforcement into federal custody.

The 2nd U.S. Circuit Court of Appeals in Manhattan on Wednesday declared the administration could not be required to release funding for law enforcement grant money to Connecticut, Massachusetts, New Jersey, New York, Rhode Island, Virginia, and Washington — all of which do not cooperate with Immigration and Customs Enforcement, a federal agency that detains immigrants who do not have documents.

The court found that the Justice Department had the authority to set conditions on states and localities it dispenses federal money to. It also noted that the Supreme Court has maintained the federal government supersedes the state on immigration policies.

“Today’s decision rightfully recognizes the lawful authority of the Attorney General to ensure that Department of Justice grant recipients are not at the same time thwarting federal law enforcement priorities," a Justice Department spokesman said in a statement issued Wednesday. "While today’s ruling is a major victory for Americans, its full scope will not be realized until the practices of granting nationwide injunctions and associational injunctions are stopped, as certain cities that are parties to this judgment may nonetheless use rulings from other courts to evade these lawful conditions."

The Manhattan court's decision overruled that of a lower court. The seven states and New York City have not said if they will appeal.

The coalition of states and New York City sued in 2017 after then-Attorney General Jeff Sessions announced that law enforcement grants require states and cities share information with Department of Homeland Security about criminals who had been arrested and were illegally in the country. Sanctuary zones ban ICE officers from working within local jails, where federal officers could previously identify arrestees who are also illegally present and then transfer them into federal custody to begin deportation. As a result of ICE not being allowed to make transfers in jails, its officers are forced to go into communities to find people they know were arrested and released by local authorities.

Funding being withheld by the federal government is allocated under the Edward Byrne Memorial Justice Assistance Grant Program, created by Congress in 2006 to make available $250 million annually for states to use on law enforcement initiatives. It is not clear how much of that funding is sent each year to New York City and the seven states involved in the lawsuit.

[Read more: 'No enforcement mechanism': Georgia lawmaker introduces bill to crush sanctuary cities]