" For example, I believe Ireland have a system where you only pay corporation tax on sales within Ireland, and none on sales elsewhere, and that's attracted many companies to operate there."
If that's the case then I'd have thought that a lot of the possible legal objections fade away. It's not that CT isn't being paid in the nation of residence, it's that CT isn't being paid anywhere. The whole thing starts to look like a complex structure whose purpose is not to pay tax and not for operational reasons. That, as I understand it, is something the tax authorities are entitled to take action against.
"If companies had to pay all their corporation tax to Ireland, it might be less attractive to move there, just for a couple of percentage points off their tax."
It's not just a couple of percentage points. Ireland's CT rate is much lower. When one regime starts undercutting tax to that extent any entity which can move there will do so; it's not possible for must of us to move to personal tax havens but for a multi-national corporation to move to a CT haven it's practically a no-brainer. How should other countries react? They could make similar cuts but the end result is that none of them win; businesses stay where they started and none of the countries collects much tax. If, however, other countries have the sense not to join a race to the bottom they lose the tax of the companies that head-quartered in the tax haven but are effectively conducting business in their territories. At the point where this becomes intolerable - politically if not financially - they need to find some other solution. If this looks like such a solution then it's unlikely to be a problem at an international level as there would be plenty of other countries looking to follow suit.