After that ruling, the Trump administration filed its own lawsuit against California over its own “sanctuary state” law, which prevents the police in many cases from holding people at the request of federal immigration agents, and limits the sharing of information about the release of some county jail inmates who are in the country illegally. In its suit, the federal government argues that the law makes it impossible for immigration officers to do their jobs. A hearing in the case is scheduled for late June.

Los Angeles has for years received millions of dollars under the federal Community Oriented Policing Services program, which is meant to promote community policing. The city police department has used the money for its Community Safety Partnership, which allows police officers to spend intensive time in neighborhoods, leading mentoring programs or coaching sports teams. The police say the program in the neighborhood of Watts has helped bring about a 50 percent reduction in violent crime and arrests.

In 2016, the city used the roughly $3 million it received to hire about 25 officers. City officials asked for the same amount of money in 2017, hoping to use it to hire more officers in a South Los Angeles neighborhood where violence had spiked.

But police departments around the country seeking a share of the $98 million pool of grant money last year were asked to demonstrate that they have a policy of alerting immigration agents before releasing inmates and giving immigration agents access to jails in order to conduct inmate interviews and review files. Departments were also asked to give federal authorities 48-hours notice before the release of any immigrants.

The Los Angeles Police Deparment did not do so, and was awarded no money. The Justice Department said the vast majority of those departments that received grants had signaled a “willingness to cooperate with federal immigration authorities.”

The city’s lawsuit argued that local governments had “an untenable choice: Commit to participating in federal civil immigration investigation and enforcement efforts, or sacrifice funds for public safety and community policing.”