The true explanation or the TV show explanation?
The true explanation is that it was a shortcut to keep the same actor already under contract on board and relevant for a final season rather than bringing in a new actor to play the role of VP.
In the show, it was never explained in detail during the season 6 finale. Santos (Jimmy Smits), never selected a VP because the race was down to the wire at the convention. He selected a VP after wining enough delegates, not before.
The race came down to 3 people. Vice President Bob Russell (Gary Cole), the favorite who had the most delegates going in, but not enough to win. Late challenger who threw his hat in the ring at the convention, Governor Eric Baker (Ed O'Neill), who Bob Russell wanted as his VP and Santos. John Hoynes (Tim Matheson) had some delegates but he was never in the running.
Santos didn't like Russell. That was a "non starter" - those words were from the show. Baker was asked (and he was considered a stronger candidate), he turned it down.
Script
Conversation between Josh & Leo after Santos got NYState on his way to wining the convention.
Josh: We still gotta line up a VP.
Leo You ask Baker?
Josh Yeah, he begged off. Doesn't wanna put his wife through it.
Leo I guess Russell isn't on the shortlist.
Josh That was a nonstarter with the congressman.
Leo: Want me to help work up a list?
Josh: No, we got it
narrowed down to the guy we want. I'm just not sure he's gonna accept.
Baker (probably) thought Santos was likely to lose and it had come out that his wife had suffered from depression during the convention, so Baker not wanting to put his wife through the race that he thought they would lose made sense. It was mentioned that Santos was likely to lose at least once.
Hoynes was never considered because of a past scandal. Josh made that clear in an earlier conversion they had.
and there was a "we discussed it" in there, and they chose Leo.
In reality, picking an aging chief of staff with alcoholism in his past, health issues and a divorce would be unlikely to happen. In the show, it was implied that Leo was a person with integrity and experience, who was the best man for the job and a good mix with Santos' youth and inexperience.
In season 7 episode 1 they go into it a bit more. The first poll comes out an Leo's poll numbers aren't good. Santos looks concerned about that. You can read the glance as you see fit, but it doesn't look like a happy glance to me. (about 14:30 into the episode).
Script
Santos: What's this?
Josh: That's Leo's approval rating. Don't worry
about it. It's not a relevant number. Sticker shock on the part of the
voters is all. It's not like he's a drag on the ticket. People are
voting for the top of the ticket anyway. We got plenty of time to pull
his numbers up.
and later on the TV screen, they say some lines not on the script, they mention his bypass, leading into this:
Limited work schedule. It's a hard sell. No doubt about it. But Santos
knew what he was getting. You don 't pick Leo McGarry as a running
mate with all that baggage because you want to, it's because you have
to. Santos needs that heft and foreign-policy savvy which he certainly
doesn't have himself.
Santos turns up the TV and listens (about 17:40). It seems, Santos isn't thrilled with the Leo pick half way into the next episode.
The whole thing was strange. Santos doesn't know Leo, maybe he picks him at Josh's recommendation, perhaps at the president's recommendation (never said, but in theory, possible). Santos was never a "take a recommendation" kind of guy at all, he was his own man. It really didn't make much sense beyond, lets put this twist into the show and keep this actor relevant. But the argument the writers made was that Leo had experience that Santos lacked. I don't see any logical way that experience trumps a bypass, a divorce, age and alcoholism and, lets not forget, Leo was never the most charming guy. He was a behind the scenes, not "win over the voters" personality. The Leo really didn't make sense when you put it all together beyond not wanting to write a new character into the show.
While maybe not related to your question, at the end of season 7 episode 1, Santos and Leo are in a room together and they connect. Santos says something like "forget about winning, I want a plan of action when I get into office" and he and Leo get down to putting together a plan. Leo knows what the job is, he knows the limitations, he knows how to work with congress, which maybe Santos should know as a congressman, but Leo knows it from the point of view of the presidency and Santos values that experience.