You're missing several stages in how the creative accounting works, and each of those stages are, separately, probably good things, which is why they exist in the first place.
Note, for example, that the UK and Germany and France all have laws that make it okay to avoid paying taxes by claiming (truthfully) that you're taxed in Ireland, according to the laws of tax residency of those respective countries.
But yes, it's an undesirable-to-collective-civilization loophole, and it'd be nice for it to be closed. I'd love for Apple to be compelled to pay more taxes. Yes yes yes! I'm surprised that the EU is making so much headway in this round, but if they fail in this round, I resoundingly hope they pass some new laws, such that they can win in the future.
The "head office" company isn't stateless, btw, and btw it technically has an office (usually a P.O. Box) and some people do work for it. There are maybe a dozen companies involved, including the actual-work-doing companies in the UK and Germany and France, and every one of those companies have an HQ in a state. I think that the "head office" is even located legally in Ireland.