An adviser to the European Union’s top court dealt a major blow to Apple in its $14 billion tax dispute with a bloc, after recommending a lower court ruling in favor of the iPhone maker should be set aside due to legal errors—a setback for Apple as EU officials argue the company used its Irish headquarters to get an unfair tax deal.