It's based on the states they have operations in (like distribution or corporate hq). Say they have a warehouse in NY, they have to charge New York residents NY sales tax. Since I'm not a New York resident (because I live in Colorado and Amazon has no operations here), I can't be charged NY sales tax. That's a pretty simplistic explanation, but that's how it works.
Amazon does not tax. The government taxes. The question should be is your local or state governement (probably state) taxing you on your Amazon transaction? If the answer is yes then Amazon just like a local storefront retailer is simply collecting the tax revenue from you to pass along to the state or local government. Do they have school where you live?