Your initial point was incorrect. Corporations do not have a moral or legal obligation to minimize tax payments. Corporations can be governed with many goals: growth, efficiency, and even social good. How you measure "shareholder value" is up to a company to decide; it's a company policy, not a law or universally accepted moral code. Most companies measure value with the stock price.
Apple is a great example of how this works, their tax avoidance did not maximize shareholder value, and was the incorrect business decision.
Apple stock is tanking right now. People did not invest in Apple because of their great tax avoidance, but because of growth opportunities. Holding that money overseas simply to avoid taxes was the worst thing to do.
You can save 40% by avoiding taxes, but your opportunity cost is a potential 1000% by failing to invest enough in growth when you have an opportunity to get a 10X return (I don't know what Apple's prior internal return on investment is, but it's probably been much higher than 10X).
The responsibility Apple had to it's shareholders was to maximize growth. By keeping international profits overseas and maintaining a very large pile of locked away cash, Apple harmed shareholders, as that money was not useful for what investors wanted Apple to do. At the least, they could have spent it on development internationally (and lose out on the US tax credit for R&D...).
Apple may have saved 40% on a fraction of their profits in tax avoidance, but the company overall has lost 20% value as investors have realized that Apple has failed to continue growing. This is an astounding loss of value during a time when their competitors' stocks are up sharply. Shareholders feel Apple has made very bad decisions and expressed that in the traditional way: selling stock (not lawsuits).
If Apple had invested that money in R&D, would their watch be more marketable, or could they have sent it through FDA trials (like many people thought they would), or maybe they would have beat Microsoft to the "Surface" market, or not be playing catch-up in the automated car market...
It's really hard to guess at the time what the right answer is. That's why guys like Jobs are so valued. In retrospect, we know with certainty that Apple's decisions were bad. With a falling stock price and stalled growth, tax avoidance by sequestering money is a negative thing.