It's because the rules let them. If a government seriously wanted to crack down on this it would be easy, but they fear all of the banks and companies headquartered there leaving.
My idea is taxation independent of where a company is headquartered (because that makes no sense, see also Cayman Islands) but instead on where they trade. If a company wants to operate in a country it has to pay tax there.
It would also force other countries to adopt the rule otherwise companies will HQ in the first adopting country unless they want to pay full tax in their HQ country and partial in the first adopting one.







