There have been many questions concerning tipping answered in the Q of the D, but I've never seen this one. If tipping at a restaurant is up to the customer based on their opinion of the level of service they received, how can a "gratuity" be automatically added to the bill?
The simple answer is, restaurants, as private businesses, can implement whatever customer policies they like, as long as they're within the law and transparent. Restaurants, like nearly all businesses, have the right to set the rules that customers must follow and automatic gratuities are among them.
That said, restaurants are legally obligated to inform customers in advance of the auto gratuity, which is almost always reserved for parties of six/eight or more. You'll either see a note in the fine print at the bottom of menus that an auto gratuity is in force or a staff member will inform the large party of the policy.
One interesting aspect of the auto gratuity, whether for a large or small party, is that it isn't, technically, a tip. Rather, it's a service charge. There's a difference, a big one, that was defined by the IRS in 2012 and went into effect in 2014.
A tip is, according to the IRS, a separate income stream for workers in tipped positions. By contrast, a service charge is compulsory and not a matter of customer discretion; therefore, it's counted as restaurant revenue. Believe it or not, a restaurant owner can choose to dole out all, part, or none of the auto gratuity to the employees.
It can get complicated when the auto grat is factored into employees' wages. In some states and restaurants, staff can be paid less than minimum wage when the supplemental tip income raises the wage past the minimum. In the case of a banquet hall, for example, where the gratuity is part of the total bill and servers do not make tips in most cases, the employer must make sure the servers are paid at least minimum wage. The nuances of this are a bit beyond the scope of this answer.
In the end, a customer can opt not to pay an auto gratuity by 1) not showing up to a restaurant in a large party or 2) not frequenting a restaurant with a service charge for large parties. Otherwise, as long as the service charge is transparent, patrons are liable for paying it.
Now, whether or not any part of the auto gratuity goes to the wait staff is another question. You can inquire, though some restaurants forbid staff from revealing it. You can understand the restaurant's reluctance. What if the restaurant shares the auto gratuity and the waiter tells you it doesn't? Conversely, if the restaurant owners aren't sharing all, some, or any of the auto grat with some poor szhlub serving a table of 10, they certainly don't want customers to know what a racket they're engaged in.
The whole thing is fraught with pitfalls and what we do, when we're subject to the auto grat, is simply pay the freight and let the chips fall where they may. We figure that if the waiters and bus people are working at the restaurant, especially these days, whatever policies are in place are acceptable enough to make their employment worthwhile. Waiters, like customers, can vote with their feet if they're not.