The only way to challenge a law in court is to break it, and sue when you’re not allowed to. You can’t just go to the court and say “We’d like to do this, will you let us?” because that’s a hypothetical situation and hypotheticals are not justiciable in most states. The Mayor of San Francisco, beliving that the law in question violates the California Constitution, elected to break the law in order to challenge it.
This is exactly civil disobedience by the Mayor and those in agreement with him, against a statute the Mayor believes to be in violation of the California Constitution; if he’s right, the law is a nullity. He is putting himself and his career on the line for this. And you have the gall to chastize him for upholding his conviction as to what the law of his state actually requires?