For statistics like these, it's necessary to take circumstances into account. Prior to last year, Messi played his entire career at the club that raised him from childhood and revolved wholly around him in every way, with generations of players who were signed and trained specifically to accommodate him. He also did so at a time when Barcelona had an unparalleled golden generation even if we don't take him into account. Meanwhile, Ronaldo has had to adapt first to the Premier League, then to La Liga at the age of 25, then to Serie A, and then back to the PL at 36. It's also a hell of a lot easier to create an impressive international record playing for Argentina than for Portugal. Outside of the World Cup, Argentina's only games in which they aren't favored are the ones against Brazil. The vast majority of their games are played against the likes of Ecuador and Bolivia. Portugal, on top their lesser footballing pedigree, have to compete against an infinitely tougher field of opponents in Europe.
If Ronaldo had come to Madrid as a child and was raised as a son of the club, with the whole team built entirely around him for every moment of his career, and stayed there for seventeen years instead of nine, it's likely that his accomplishments would have surpassed Messi. The fact that he's even close despite taking a much more challenging path says a lot. Instead he has had to prove himself at United, then go to Real Madrid at a time when their main competitor was the best team in the history of the sport, then go to Italy to play for a diminished Juventus side, and then back to the PL to play for a club that has been in freefall for a decade. For there to even be room to discuss whether he or Messi had the greater career, when Messi has had every conceivable wind in his back every single moment of his career, is nothing short of amazing. Imagine if Ronaldo's circumstances had favored him that much. There might not even have been any debate about which was the greater player.
If I run 25mph in a pair of Puma Bolt Evospeed Runners and you run 24mph in a pair of Converse high-tops, who's the better runner?