This is not exactly true. In regards to tourists visas, the law is almost always about not working locally.
Most foreign governments don't care at all if as a foreigner you work from your laptop for a foreign company. You are not taking any jobs away from the locals, and you are still spending money in their country.