This comes down to the same reason why when you click "buy" on some website, they can't say "oh look we added a secret X% f** you fee!". Similarly, this is the reason why when you negotiate a rate with a lawyer, accountant, gardener, or other professional, they can't add random fees that weren't discussed. My climbing gym has had big signs up and has sent myriad emails over the past few months leading up to a new credit card processing fee for this very reason.
If you had great service, I would still recommend fighting this and then tipping the server directly with cash. These "mandatory tips" don't go to the server, but are usually pooled and mostly taken by management. If the restaurant is one of the few ones that is equitable between the staff members (e.g. if the tip gets automatically split between front and back of house), then that might be the one exception where paying a surprise mandatory fee would be okay.