So let me get this straight, in order to defeat the villain, the Avengers made a worse villain?
That first villain, Ultron, the living automaton with artificial intelligence and massive daddy issues about its creator Henry Pym, had made things pretty bad in the [[[Age of Ultron]]] mini-series. “Pretty bad” being a euphemism conquering the world, destroying major cities, killing people, and generally not playing well with others. In order to undo the Age of Ultron, Invisible Woman and Wolverine went into the past and visited Henry Pym before he built the first Ultron. They told Dr. Pym that Ultron would destroy the world in the future but also told him he still had to build Ultron so that the time line would stay the same until just before Ultron started the Age of Ultron. So Pym built Ultron, but put a kill switch into Ultron’s A.I. so that Ultron could be defeated at the right time in the future.
Cut to years later and the right time in the future: Invisible Woman visited Dr. Pym again. She showed Dr. Pym, whose memory of the earlier visit had been wiped, a video about Ultron which included instructions on how to activate the kill switch. This occurred just before the events of The Avengers v.4, # 12.1, where, you may recall, the Avengers rescued Spider-Woman from super-villain team the Intelligencia but inadvertently reactivated Ultron. (You may recall it. I had to look it up.)
Because he had been warned, Dr. Pym could change what happened after the Avengers reactivated Ultron. This time Ultron didn’t get away. Instead Pym had Iron Man upload the kill switch activation codes into Ultron. Then, after Ultron shut down, Pym used a computer virus to destroy Ultron. And they all lived happily ever after, no?