Mayors in at least seven major U.S. cities reaffirmed their commitments to shelter undocumented immigrants from federal immigration authorities after Republican president-elect Donald Trump said he would block federal funding for “sanctuary cities.”

Sanctuary policies vary by city. Typically, local police refrain from helping federal authorities identify undocumented immigrants for deportation, unless they have committed serious crimes.

The San Francisco-based Immigrant Legal Resource Center counts five statewide laws or policies, 365 county policies or ordinances, and 37 city-level policies putting some limits on these requests.

Following Mr. Trump’s election, Democratic mayors in cities including New York, Chicago, Los Angeles, Seattle, Philadelphia, San Francisco and Providence, R.I., among others, said they would challenge any Trump administration move to crack down on illegal immigration.

Many billions of dollars could be at stake. For instance, San Francisco alone gets about $1 billion annually from the federal government, both directly and through the state, according to Ben Rosenfield, the controller for the city and county. The city is “assessing budget impacts from possible federal actions,” but support for public health and human service programs could be affected, he said.

Chicago Mayor Rahm Emanuel, center, is one of several city leaders who has said that city services won’t change for people, regardless of their immigration status, as ‘sanctuary cities’ face opposition from the incoming administration. PHOTO: TERESA CRAWFORD/ASSOCIATED PRESS

Presidents have limited powers to strip federal funding from local governments without the express approval of Congress, say legal experts. This is especially true in regard to mandatory expenditure programs, like Medicaid.

The Trump administration would have more leeway to suspend or slow the allocation of discretionary grants, particularly those related to criminal justice and dispensed by the Justice Department or the Department of Homeland Security, said George Washington University constitutional law professor Jonathan Turley.

With those funds, “there’s a great deal the Trump administration could do to carry out the threat,” he said. The Trump administration could also steer more grant money to cities that cooperate with federal immigration laws, he said.

Presidential spending power has been a contentious area of law, especially during the Obama administration, and Mr. Turley said he would expect that cities would go to court to challenge any effort to financially punish them for sheltering undocumented immigrants.

Immigration and Customs Enforcement can enforce federal immigration law without cooperation from local authorities but protective policies at the local level make the agency’s job more challenging.

At issue in many localities is a practice by the Department of Homeland Security to identify a potentially deportable individual in jails and issue a “detainer,” which can extend detention even for low-level offenders.

Some cities argue it isn’t their role to enforce immigration laws and doing so sows distrust between communities and police. Some courts have ruled against the use of detainer requests. The Northern District of Illinois ruled in October that detainer requests by the Chicago field office for ICE exceeded the government’s authority to detain immigrants without a warrant.

Los Angeles doesn’t turn over people arrested for low-level crimes to ICE. Philadelphia won’t cooperate with detainer requests unless the person has committed a first- or second-degree felony involving violence. Providence continues holding only individuals subject to a criminal detainer, meaning they were convicted of a prior crime, typically a felony.

Sanctuary polices don’t deter federal agents from conducting operations to find undocumented immigrants. Federal agents routinely identify child molesters, gang members and other criminals for removal even in sanctuary cities by going into communities, thanks to their own intelligence-gathering.

Some localities actively partner with ICE, and some have aggressively pursued undocumented immigrants through their own programs. In Arizona, Maricopa County Sheriff Joe Arpaio faces a criminal contempt-of-court charge for defying a judge’s order to stop conducting immigration patrols. His lawyer has said he will fight the charge. The sheriff lost a re-election bid last week.

More than 2.5 million people have been deported by the Obama administration. It has prioritized the removal of convicted criminals and recent illegal border crossers, which isn’t dissimilar to what president-elect Trump suggested would be his administration’s emphasis in a recent interview on CBS’ “60 Minutes.”

Republicans have criticized noncompliant jurisdictions. The Republican-controlled House of Representatives passed legislation last year that would withhold federal, law-enforcement grants from cities that shelter undocumented immigrants. President Barack Obama said he would veto the bill and Senate Democrats blocked a version in that house.

The term “sanctuary city” is ill-defined, said Los Angeles Mayor Eric Garcetti, a Democrat.

“We would not like to lose federal funds,” Los Angeles Police Chief Charlie Beck said Tuesday. “But I will tell you this: Whether or not I do the right thing is not a matter of money. This is a matter of principal.”

On Thursday, Los Angeles City Council President Herb Wesson said he would introduce a motion next week to protect the city’s sanctuary status. The motion would include steps such as identifying all federal grants, loans and other funding the city receives, creating an immigrant advocate and a committee on immigrant affairs to “develop a comprehensive set of strategies and plans.”

“Los Angeles is a melting pot of hundreds of ethnic groups, languages and religions,” Mr. Wesson said. “Let us lead by example in practicing tolerance and acceptance rather than malice and hostility.”

San Francisco Mayor Ed Lee, a Democrat, said, “We stand united in our commitment to protect immigrant rights and provide refuge for those in need.”

The city faced an outcry last year after an undocumented Mexican allegedly shot and killed Kathryn Steinle, 32 years old, as she walked with her father along Pier 14. Local officials ignored a request from federal officials to have the man held despite his criminal record and five previous deportations. Politicians from both parties criticized the city for letting the man, Francisco Sanchez, go, but the city’s Board of Supervisors voted unanimously in October 2015 to keep the policy in place.

Chicago Mayor Rahm Emanuel, a Democrat and former chief of staff to President Obama, on Monday instructed operators who handle calls to the 311 city services line to assist residents with fears about legal status, adding that jobs programs and hospital services “will always be there” for people, regardless of their immigration status.

New York Mayor Bill de Blasio, a Democrat, last week said he would fight efforts to deport people in the city and would consider destroying a database the city maintains for a program that provides identification to people in the city regardless of immigration status.

“We are not going to sacrifice a half-million people who live amongst us, who are part of our communities,” he said. “We’re not going to tear families apart.”

“Folks are scared,” said Providence Mayor Jorge Elorza, a Democrat. The city of about 180,000 people is 44% Latino, and his message for residents is “they are safe and we have their back.”