In the same way, someone who robs a bank is (perhaps) acting optimally for someone whose goal is "get money" and who doesn't have other goals like "don't break the law" and "don't take stuff that isn't yours".
And if someone sleeps with your spouse and then kills you lest you take revenge, then (provided they do it carefully enough) they may be acting optimally for someone whose goal is "sleep with that person I fancy" and who doesn't have other goals like "don't encourage people to cheat on their spouses" and "don't commit murder".
If someone says "X acted obnoxiously" or "X acted immorally" then pointing out that there's some unpleasant/immoral set of goals X may have had that for which their behaviour was optimal misses the point of the criticism, which is to say "their goals apparently don't include being a decent person". hellofunk wasn't saying that Schwarzenegger was ineffective but that he was a bad person.