SAN FRANCISCO—California and San Francisco are challenging the Trump administration through separate lawsuits over its decision to withhold federal grant money from cities that refuse to cooperate with federal immigration enforcement.

The lawsuits announced Monday are the latest attempts by a number of cities and states to push back against the Trump administration’s immigration actions. So-called sanctuary cities have vowed to protect undocumented immigrants, who they say are vital to their local economies and integral to...