The X series ends sometime after the last X game - when Zero admits himself to a research institute since his body still contained the Maverick virus. As such he went into a coma so his body and mind could be studied - the researchers made sure to back up his mind and memory. The Cyber-Elves (basically A.I. fairies for all intents and purposes) are invented by studying Zero alongside the Mother Elf, which was created specifically to counter traces of Sigma's programming. In fact, the Mother Elf helps to purge the virus - and the government planned to make sure to clear all cured Mavericks of all charges. X himself and most of the scientists involved want to ensure humans and Reploids can coexist after all.
However, Dr. Weil (presumably not related to Wily) is not on board with this, and he has grown to increasingly hate Reploids due to the events in the X series. As such he hijacks the Mother Elf as well as Zero's original body - repurposing both as the elf-controlling Dark Elf and the weapon Omega. With that Weil instigates the Elf Wars; using the Elves as proxies and hacking tools to make Reploids go berserk in an effort to wipe the Reploids out. As a response X made sure that Zero's original mind was transplanted to his clone body - his MMZ body - and both of them took out the Dark Elf first - forcing Weil's hand,
Weil unleashes Omega, and the original body combined with Weil's footsoldiers go on to slaughter humans and Reploids en masse until X and Zero stop them.
With 60 % of humans and 90 % of Reploids dead (and remember, the X series were supposed to end with X5, another near-total extinction) Omega and Weil are sealed away (in a pretty idiotic move), Zero goes into a coma and X - in another idiotic move - seals himself with the Dark Elf without telling anyone. Thus resulting in one of the scientists' descendants - Ciel - creating a Copy X to help guide the remnants in the Neo Arcadia state. Copy X proves pretty unstable though...
So the Zero series starts with Copy X ordering a clampdown on Reploids, an Resistance forming against that with Ciel as one of the head figures, and Ciel stumbling upon Zero's comatose body while being chased by Neo Arcadia forces. She realizes that the comatose Zero body is the legendary Zero, and uses a Cyber elf to ressurect him (even if he's amnesiac at first).