The more simplified answer : If I was an Indian working in America, and took X amount of the money I was making in America, and paid my income tax from that money back to India, all the while using AMERICAN public services, I don't think Americans will be very happy with that. If I am using tax-funded utilties like roads etc., I would be expected to pay income tax in that country, from my income in THAT country.
However I would not like to pay income tax to BOTH India and America on single salary. Hence the treaties to avoid double-taxation.
Problem arises when I pretend to be have the income "generated" in whichever country has the lowest income tax. That should NOT be allowed. You pay sales tax as an individual. But do you as a person get to pretend that your salary earned in USA was "generated" in Ireland, and therefore pay no tax in USA, and only a tiny amount in Ireland? Why should the corporations get to pretend that, then? This is not "tax optimization".
If I lived in India, the indian government will actually deduct income tax at source. This is a really good idea. It means that the rich don't get away with paying just .002% while rest of us paid through the nose. Income tax should always get deducted wherever the income is actually generated(i.e. where you get paid), right at the source, and paid to THAT government. It definitely will involve a total rethink of international trade workings, but it is not like the current system is working well, based on all the poverty and starvation we have, while a few people just get off on seeing zeroes add up on their bank account, without ever actually spending all that money for anything.