It was a good outcome but hell if I know why he did it; it was a 180 from his earlier stances. I don't think we're seeing a new, kinder & gentler McCain here.
My suspicion, as long as we're speculating, is that Trump/Ryan/McConnell finally managed to go too far. Not in an immoral sense -- as if McCain gives a shit about his constituents -- but in a douchebag sense. McCain's old, he's dying, it's very likely his last term, he was pulled out of treatment for the sake of someone else's legacy. At some point the mistreatment gets personal, and he's at a point in his life where you really can't hurt him with anything. What are they gonna do, threaten a dying man with a primary? But the whole time they're putting him through this miserable process, they've been Grade-A assholes to him, treating him like shit, and smirking smugly like they're going to eventually get everything they want.
So what better revenge than to give the vote they asked for and then hand the most backstabbing, self-serving bunch to disgrace the halls of Congress a well-timed Lannister-style knife in the back. He'd been the GOP's obedient dog but at some point even a beaten, emasculated mongrel like McCain just runs out of fucks to give and bites back. When that happens, the bully is never prepared for it. Why would they? Beating the cowering mutt worked for so long, after all. They probably figured he was completely dead inside by this point.
Whatever it was, I'm glad he had a spark left. Turns out bullshit is flammable.