You're giving AI way too much credit.
Most likely, AI really didn't optimize anything.
It most likely engaged in a probability driven selection process that inevitably lead to the most powerful weapon available.
Change the goal, change the result.
Yes. The tricky part is recognizing the need to change the goal.
Achieving this implies you already have an answer in mind that you want to lead AI toward. And AI is often happy to accommodate --- because it is oblivious to any consequences.