AI doesn't "accidentally" do anything. Models have to be trained 1) by providing examples on how something should be done, an 2) by rewarding correct behavior to reinforce algorithm weights.
Someone (Google) had to provide the instruction and repeatedly reward the behavior to get to the point where the AI could even connect to the target websites, let alone "hack" into them.