McCain is neither a liberal nor is he a conservative; he's a political opportunist. He was conservative when conservatism served his purposes, such as during the Reagan administration. During the Clinton administration, he did nothing about x42's decision to gut the military. When the political winds began blowing the other way (abetted by having the 2000 nomination "stolen" from him), he began drifting leftward. He sees some advantage in being green, hence his climate change conversion.
Finally, he has no compunction about stabbing anyone who stands in his way.