Short Answer of the Legal Gray area in between that needs Juris Prudence:
In general, Tourist visas do not allow you to work as employed in the issuing country. But, they do not prohibit you from doing your 'home' work while on vacation.
There are explicit things and implied concerns here and will vary from nation to nation.
Before laws can be created, formulated, articulated, ratified and then be approved by a Nation's legal / govt system there is certain amount of Juris Prudence that has to be undergone to establish ground, premise, case & jurisdiction for how those laws would be established & executed.
Pertinent Question to ask: What Counts as "Working" in a scenario ?
FINANCIAL INTERCHANGE or PAYMENT or TRANSACTION that a NATION or GOVERNMENT finds UNDER THEIR PURVIEW or JURISDICTION and /or their INTERESTS and APPLY LEGAL, FINANCIAL, TAX & Other Ramifications to those said INTERCHANGES.
AND in EXECUTION,
Then its ability to TRACK, DETERMINE APPLICABILITY, ELIGIBILITY or COVERAGE and ENFORCE the above.
PS: E.g. US Citizens are taxed in certain manner irrespective of where they are, but they can't or don't tax them on EVERYTHING, EVERYWHERE.
But, we must first ask what counts as "working" in said Nation "X" under a "tourist visa"?
Typically, a Work Visa (or Legal Work Permit/ Eligibility) or similar Professional/ Business is required if your intent and action entail "work" that has legal/ financial implications in the said Nation.
Basically, its a legal approval or disapproval to engage in "RECEIVING Financial Payment for SPECIFIC ACTIVITY" under the said Govt & Jurisdiction.
So what counts as work?
For a chef cooking a meal for his friends in destination? But, if he is not being paid for it in a legal/ financial binding as per regulations/ jurisdiction of a country, then is he working from the point of view of that country?
In an emergency, if a medical doctor on vacation provides some help to someone, without any payment; does it count as work?
If as an international lawyer, I advise a cousin on how he should tackle something legally, without any fee etc., does it count as work?
Again, leaving the "medical/ legal practice" privileges aside, these things TYPICALLY do not constitute FINANCIAL / LEGAL WORK ACTIVITY but as PERSONAL ACTIVITY due to LACK of FINANCIAL INCENTIVE or TRANSACTIONS, which would come as being under the purview of "requiring a work permit" from the Nation.
Now, there are plenty of professionals and entrepreneurs who are jet savvy frequent flyers, hopping between client meetings, conferences/ exhibitions, networking meets etc., while at the same time continuing to "do their work", at times even on vacation.
So, which part of their "work" should/ could fall under "legally working" v/s "illegally working"? Typically, when an nation gives a Work/ Business Permit, it entails to the individual or entities "legal eligibility / privilege" to earn money; i.e. salary or revenue from "legal entity" IN that Nation or some kind of financial/ legal activity that comes under its jurisdiction/ purview
So, if I operate out of Nation A, my client is in Nation B, and I am passing through Nation C for a week long conference while continuing to work on proposals and projects for my client, am I violating "legal work privileges" of Nation C? If, that would be the case, there are tons of people who are currently working illegally.
Would it even be possible for me to ask Nation C for a "work permit"? They would pretty much say, that does not fall under their purview.
Even if they wanted to the Nation cannot offer any "work permit/ privilege" for the person/ entities work in the said Nation, as that work is out of their financial/ legal jurisdiction.
I believe, Work/ business when outlined in any nation is related to work/ business that falls within the jurisdiction of their legal / financial frameworks - whether local or international.
Work vs Residence Tax?
On the other hand, residency parameters where a person is liable for taxes beyond X number of days is another legal/ financial regulation per se. But, that is related to TAXATION, not legality to do what they do.
Exception being if staying beyond a set period (e.g. 180 days in some places) makes you eligible / liable to pay taxes.. I think the OP was asking in general. For perpetual stay, the laws may be different for all nations & their treaties.. then again, hard to enforce for remote work done on a laptop.
So anyone from the US who is working on their laptop or smartphone for an entity and earning salary/ revenue from an entity that has no legal / financial relationship with the "passing through/ touring through nation" while on short or long vacation is not under any penalty. Why?
Again, as we get into international laws, multinational businesses & corporations who have legal/ financial footprints across national borders, expat assignments & intra-company transfers (employee transfer in an MNC from their department in Nation A to Nation B), this question becomes more complex, and better suited for the "Expat & Legal/ Immigration/ Taxation/ Business" areas.
Most people end up doing their work/ personal stuff while traveling as long as no "financial/ legal premise or interchange is established" between said entities/ parties under the JURISDICTION / Legal & Financial Frameworks of the said Nation; as long as your US employment i.e. employer-employee relationship has no direct legal, financial bindings with the destination country of tourism or TRANSIT, you should not come under the said Jurisdiction.