Generally, getting caught WFH in another country results in immediate termination. For cause, because working in another country creates an entire set of legal, financial, and tax consequences that the employer may not be aware of or prepared for.
If you do everything by the book, it's really hard - practically impossible to do fully legally.
Most countries won't issue you a work permit without a lot of paperwork, cost, and time. Think 'send your passport off to the embassy for 3 months' type hassle...
And most employers don't want to employ someone abroad. Employment law varies widely by country, and unless they already have an office in that country they don't want to do all the tax and reporting stuff for only you.
Long term abroad in one country might be doable, but 30 days in each country is pretty much impossible.
But for example in my case, I do still come back to my home country for decent chunks of time that still adds up to around half the year. I'm working for a US company and every country I have visited thus far mention it's perfectly fine to stay and work for some amount of time (usually 90 days) as long as it's not displacing a local job. I'm not a tax expert or anything but I don't see what the issue is here or why I'd need a work permit in the first place?
Because you're usually on a tourist visa and those will say something about "not working" with varying language. Since your "working" looks identical to "dicking around on a laptop" it's unlikely to draw attention, but if you were to piss off the right person at the wrong time, they might be able to drop a train on you (but even then the most likely thing is being kicked out of the country, but some countries could get very "spicy").
Of course, if you were a rock star coming in to perform, they'd definitely want their cut even if you were only performing for a day. The laws haven't advanced to cover this situation entirely well, so there's a lot of leeway on what you can get away with.
You don't generally need a work permit though, unless you are taking a job with a local employer. Generally they will have rules for how long you can stay in the country while working for a foreign employer. As long as you maintain tax residency wherever you are "from" nobody bats an eye.
If what you really want to do is live and work in one country while pretending that you live and work in another one, I don't see why either country should facilitate that.
It's easy enough to do that "properly" too, form a company or self-employed tax status in the country you are living in, and invoice the company in the country you work for. Then they aren't in a compliance issue and you are paying taxes where you work and live.
Generally they will have rules for how long you can stay in the country while working for a foreign employer.
only if they offer something like a digital nomad visa. otherwise, usually you are not allowed to do any work at all on a tourist visa, even if it's remote work to your home country. nobody cares if you check your work email or do some small stuff, but technically no work is allowed.
form a company or self-employed tax status in the country you are living in
in most countries you can't do that as a foreign citizen unless you have a proper visa for that. you can probably open a company in a foreign country, but you likely still need a work visa to actually work for your own company. otherwise anyone would just go to open a company just so they can live and work in that country.
You are (generally, it's a complex subject) not liable for taxes in a country unless you're resident.
The country where you are resident (or resident last if you don't qualify for residence anywhere in the current year) will want taxes on your worldwide income.