The MPG shown on most dealer certificates is an "EPA-estimated" mileage. That means that the EPA has taken data about the fuel and exhaust systems and extrapolated what sort of mileage can be achieved in optimal conditions. Most drivers do not drive optimally. Tire air pressure, hard stops, fast starts, speeding, hills, etc. all bring down mileage. It is possible to meet and/or exceed the listed MPG, but it definitely takes a change in your driving habits.
As to why it's legal.... the sticker admits that it's only an "EPA-estimated" number. It's our own fault as consumers that we've decided to ignore the implications of that warning. It's like eating that pint of ice cream because it 'only' has 10 grams of fat without reading the health info closely enough to see that its 10 grams per serving, and the pint contains 2 servings.