If it’s mandatory, it’s not a tip, it’s a service fee, and an enterprising tax collector could argue that sales tax should be applied.
A crusty customer could argue that he price on the menu must include the fee or rather that the restaurant provide the meal for exactly the price on the menu.
a tip is a gift in gratitude for services rendered.
My solution to this little scheme would be to make every effort to eat anywhere else but San Fran. I may just be a rebel and am getting old and cranky but I dig my heels in at anything “mandatory”. Fight it tooth and nail out of principle lol