Rinse and repeat.. tons of companies have done this. So sure some investors will eventually cash out but companies should also be taxed if they derive some benefit from the country they are from or selling products. I would argue those taxes should be low but allowing companies to totally dodge them seems like a bad setup long term.
I feel like this must be against the law somehow, but I don't quite understand where the line is.
Honestly: because you're not rich and connected enough to have the rules written for to your benefit your naked self-interest. If it was legal and economical for ordinary people to evade taxes, too many people would do it and the country would collapse.
Wages are taxed differently than a company's income. If you were to distribute the income to yourself every 2 weeks, you'd end up paying all the same taxes as wages.
Which is why a country like Belgium can be a Tax Haven for companies and have the world's highest income tax at the same time.
Also the situation you describe would make your life incredibly complicated. The logistical hoops necessary to pay your rent make it extremely unappealing, IMO.
Maybe your company has to sell something to be legit? Okay, you sell the people who are paying your company toothpicks. They pay your company for the toothpicks, the labor is just incidental.
The ultra-wealthy and big corporations take advantage of schemes to lower their taxes.