You are mixing morals with laws. The two do not always match.
It may be legal to funnel taxes out of a country where you make your profits, but I have not yet seen anyone make a convincing argument that it is (morally) right.
A lot of things are legal, but not moral. Lying to your best friend, cheating on your wife, pissing in the pool.
On the other hand, there are things that are moral, but illegal, usually because laws change slowly or don't cover all edge cases. Fortunately, many countries have a permissive judicial system where a judge and/or jury can decide that yes it broke the law, but in this particular case it's (morally) right to let it go unpunished.
They are not the same. Tax evasion is illegal, tax avoidance is at the very least a gray area, and in the extreme way most corporations implement it, certainly not moral.