Just posting to clear some (potential) confusion: As a member state of the EU you are not allowed to give selective tax advantages to specific companies. Such agreements are unenforceable.
There are specific subsidies and incentives you can give as far as I know (e.g. to keep a steel-dependent area employed), but they need to be cleared with the EU first and based on economic necessity.
Reason being that said deals are considered to create an uneven playing field for those companies that do not get it, especially SMEs.
So Ireland can set the tax rate wherever they want it to be, as long as it's equally applied to all companies. No issue there.
If a country violates said rules in a specific arrangement, they are obliged to correct the situation and the specific tax deal is null and void under EU rules. So Ireland is forced to collect the tax as if the agreement doesn't exist. They didn't have the right the offer the deal, so they have to collect. They made a promise they weren't legally able to make. At least that's what the judge seems to have said.
Apple and Ireland aren't the first and only by the way. Starbucks, Fiat, Amazon, a specific Belgian regime applying to several multinationals are also targeted.