You can do something perfectly legal in a given country, but then get denied entry to the USA because it's illegal there.
It's like driving your car at 150mp/h on the Autobahn in Germany, but then being denied entry to the USA because driving at that speed on public roads is illegal in the USA.