What Apple did is not legal, hence the fines, back taxes, etc.
The fact that the Italian tax authorities
settled for about a third of the corporate taxes they claim Apple didn't pay should be a clue of who had the weakest case. But, Italian tax authorities could drag this out as long as they wanted, and find a judge that would rule in their favor. Apple made a "business decision" to settle the dispute at a significant discount.
If you have ever dealt with a tax agency, you would understand that "legal" is an opinion, not a matter of law. Tax law is rarely black-and-white, especially for a matter of this complexity.
In the US: if you call the IRS and ask for an interpretation of the tax code, the IRS's advice is not legally binding. Even though the advice was provided by an IRS representative, the IRS has no obligation to honor it. This is in direct conflict with the legal principle of "equitable estoppel", which says that a legal authority cannot advise one action, and then turn around and prosecute you for following it.
The IRS will only honor what it calls a "private letter ruling". However, you have to request it, provide a specific set of circumstances, and pay a fee. But, only the requesting taxpayer can depend on it -- it doesn't set a binding precedent for other taxpayers.
A binding precedent can only be set by the Tax Court, unless the taxpayer elects for the simplified procedures for disputes under $50,000. But, since other federal courts also hear tax cases, it's possible for different interpretations (and precedents) to arise.
I don't know the specifics of the dispute between Italian tax authorities and Apple. But, the leadership of Apple has a fiduciary duty to follow the laws to the best of their knowledge and ability. They wouldn't have done this without paying attorneys and accountants a lot of money to interpret the law and established precedents. This same methodology is being used by many multinational companies, so it's not unique.
The difference: Apple has probably made more profit than anyone else. So, when the Italian tax authorities decided to "reinterpret" the law, you can guess who was their first target.