You've already read the title so let's get to the point: Mega Man X7 has the most coherent story of any X game that tried to have one as opposed to an excuse for you to go shooty bang bang on the meanie heads.
Mega Man X4
I get what they were going for but it's like you're only getting bits of the story after somebody tossed the Cliffnotes into a wood chipper.
The game kicks off with a dragon that appears to be from Repliforce knocking out the power to a floating city, causing it to crash into another city on the ground. Then the Colonel of Repliforce appears and gets into an argument with your chosen character, who orders him to surrender. Instead of addressing the whole "One of our units just destroyed two cities" thing or even claiming it wasn't from Repliforce in the first place, the Colonel basically says "How dare you accuse us of being Mavericks, for that we're going to go Maverick!" and the General calls for a war for independence. A war that either consists of X or Zero killing seven* Repliforce solders, or happens entirely off screen because to actually see any of that war would eat into that anime cutscene budget.
* Magma Dragoon wasn't part of Repliforce, he was a Maverick Hunter that turned traitor. Speaking of which, when did that happen? We run into him in the intro level where he tells us to get out before it crashes, then suddenly the game is telling us he's a traitor. He only reveals he let the Sky Lagoon fall in his pre-fight banter. It would have made more sense if laughed about it in the intro level. Come to think of it, the whole "telling us something's happening instead of showing it" is the overall problem with Mega Man X4's story.
It's also bizarre how Zero and Iris act like they already know each other, when the player has never seen this Iris chick before. Xtreme 2 would go back and try to fill this in (which I swear is the sole purpose of that game), basically making Iris a navigator like Alia, but for X4, Zero is basically losing his shit over a girl he just met.
"Oh for crying out loud, it's a Mega Man game, the story doesn't matter."
Then why does the game keep bringing it up?
Mega Man X5
In the opening stage, X and Zero destroy a giant Sigma head which unleashes the Sigma Virus all over the Earth, like Martin Sheen's plague in the Spawn movie. This also somehow spreads to a space colony, Eurasia, (maybe Sigma infected it through the Final Weapon in X4?) causing it to come hurtling towards the Earth. And despite the Sigma Virus being a computer virus, somehow it even affects humans, animals, and plant life. Though this is the game that introduced Reploids having DNA and antibodies, so who the fuck knows.
But things go off the rails in the endgame, which feels like it was written with the intent or Zero turning evil i.e. the bad ending. Why does the Zero Virus become a thing and create the final stages when the colony crashes and Zero goes evil? Because Zero's fused with the Sigma virus and the viral saturation at the Eurasia crash site is warping reality. Why does it still happen if he destroys the colony and stays sane? Fucked if I know! Why do X and Zero fight when Zero goes evil? Because Zero's gone evil. Why do they still fight if Zero's sane? I guess Zero goes down first but X becomes concerned about his reaction to the virus and decides to haul him back to base by force, and whatever character you pick is whatever side of the story you get. But it's bizarre that the two are still trying to kill each other and get over it right afterward. Also, X3's ending foreshadows X destroying Zero, which only happens in the bad ending of X5... maybe, he doesn't actually get the killing blow in.
Regardless of the outcome of the X vs. Zero fight, a mysterious puppetmaster steps out of the shadows and is revealed to be... Sigma!
... Did I turn over two pages at once? We're trying to make a plot twist out of the thing that was established at the start of the game, that Sigma's back?
Also, Wily is still around and working with Sigma which isn't "Somehow Palpatine returned" levels of bullshit, but it's getting there. And the images of Light in the armor capsules are no longer pre-recorded messages, but sentient so either he's a ghost or he uploaded his consciousness into a computer. I hear the Japanese version of X2 implied Serges was Wily in a robot body so Japanese players at least had some buildup, but that was removed in the English version so for everyone else the "Wily is still alive" twist comes completely out of nowhere. And future games, as far as I know, don't bring it up again.
Mega Man X6
Maybe if Capcom had bothered to properly translate this game I could tell what the fuck is going on. Eurasia was destroyed, but debris from it pelted the Earth and killed everything anyway because your efforts are pointless, silly player. Then this brilliant Reploid scientist finds a piece of Zero among the Eurasia debris and I guess uses it to empower himself, create hallucinations as part of a Nightmare which Alia says is an artificial virus (as opposed to all those naturally occurring computer viruses, I guess), and revive a bunch of his dead creations? And he also used it to bring back Sigma? And Zero comes back to life (again) after "hiding himself while he repaired himself." What did he do, drag himself into a cave with his one functioning arm and eat rocks to rebuild himself?
Mega Man X7
A vigilante Maverick hunter group called Red Alert popped up sometime after X6, but when they start acting dodgy one of their members, Axl, gets the hell out of Dodge. His breakout causes a ruckus that draws Zero's attention, and during his investigation he apprehends Axl and hauls him back to Maverick Hunter HQ for questioning. Red Alert's leader, um, Red demands Axl's return which X, Alia, and Signas are willing to comply with, but Zero smells something fishy and takes Axl to sort Red Alert's shit out. Whereupon they discover Red Alert had been infiltrated by their old friend Sigma, who was interested in Axl's transformation power and was pulling Red's strings to get to him.
I didn't say it was a brilliant story, but really, the only question I have is why X is such a whiny bitch all of a sudden.
Mega Man X: Command Mission
Does this count? I don't know where it fits into the Mega Man X cannon, as Sigma is completely absent and the big baddy is a new guy named Epsilon in a plot concerning some magic macguffite. But things don't really go off the rails until the final chapter, when a character is revealed to be another character which completely devalues an earlier scene, and you end up in outer space fighting a Final Fantasy god with the power of friendship.
Mega Man X8
Actually, X8's story isn't so much incoherent as poorly thought out. The latest batch of Reploids (which Axl was the prototype for) are supposed to be immune to the Maverick/Sigma Virus, but they start going Maverick anyway. Turns out, they literally have a piece of Sigma in them to... create antibodies, I think? and it allows them to go Maverick as they please. Wasn't the point of the Reploids that they have free will? Why is having a piece of Sigma necessary for them to turn on the humans? If the unexpected side effect was they started turning into clones of Sigma (because all of the new Reploids are supposed to have Axl's transformation power), I could have bought that.
But X8's greatest crime is ending on a cliffhanger that will never be resolved, because Capcom loved pulling that shit on Mega Man.