Ocelot used Snake to destroy the AI after enlisting Naomi to help him. Simple as that.
From the beginning, in the fallout of Zanzibar's destruction, they knew they needed to take JD offline in order to wake Big Boss from his coma, without killing him, but didn't actually know how to accomplish that.
So MGS 4 frames it that Ocelot's actions and influence on the events in MGS 1 and 2 was a process of trial and error to expose deficiencies and loopholes in the AI's MO to keep the global economy and geopolitical dynamics in homeostasis.
JD, acting as a kind of hypervisor for the other AIs, has the ability to adapt and implement different conditions and events to reach desired outcomes that would fulfill its programmed mission. Because of that, it's assumed that they have to infiltrate it directly or destroy it through the physical mainframes that are hosting it, but they don't know where JD is physically located until they hijack the GW AI through the events of MGS 2. In learning JD's location, they also find Zero's. Then they run into another issue where taking the system offline outright would "basically" cause global society to collapse along with the world's digitized militaries, due to SOP, the result of the S3 trials, being pulled offline along with GW and JD, so Ocelot, posing as Liquid, decides to take control of the system instead using the GW AI.
They intended to get Solid's DNA via Naomi, to be able to access GW under circumstances not stated, but as it turns out, neither He nor Liquid were genetic matches, so they have to resort to using Solidus, assumed to be Big Boss by the Patriot AIs.
At this exact point, I've lost my place in this shit heap so I can't write anymore.
Somebody else can iterate on this and about Naomi's role in creating the virus that would, I'm assuming, flash the AI or modify it, or some shit, because destroying the AI in the end while leaving the rest of society intact IS a total cop-out