The situation is of course different with taxes, where your "tax residence" (as we call it in Europe) lies in the country that can be objectively called your home/base (based on dozens of criteria), sometimes regardless of where you actually work. However it can be perfectly legal to pay your (income) taxes in a country where you can't legally work because these are two different things, and not paying the taxes would be illegal.
I can't be employed in a USA company (even remotely) because I don't have work visa, but I can have US clients and travel to the US (even for business - see B1 visa). I can't work from there not because the visa forbids it, but because that would mean I'm generating income on US soil, which I'm forbidden by a different law.
This situation is very different in Europe and Asia, the United States are well known for their draconic tax laws.