No, Profit shifting is not illegal. It is a tax planning strategy used by multinational companies by using the loopholes in the taxation system. You can read about the Base Erosion and Profit Shifting (BEPS) – Issues, Measures taken by India in the given link.
Further readings: