Apple considers that all sales across Europe actually happen in Ireland, so taxes on profit on sales in the whole EU are paid in Ireland. That part is perfectly legal within the EU.
The issue is that the normal tax rate in Ireland is around 12%, and Apple uses accounting tricks and tax exceptions to lower their effective tax rate there to 0.005%. That is the part that the the European Commission ruled illegal.