Aside from the answer that Aragorn had special powers of precognition beyond even those of a normal dunedain or even Numenorean (Tolkien writes that Aragorn despite the thousands of years was more like Isildur than any of his forefathers... almost an atavistic throwback to a "pureblood" Numenorean lord with all of their superpowers). Keep in mind that even Denethor is described as having insight and precognition beyond mortal men to perceive upcoming events (even Faramir had precog dreams and understanding) and Aragorn was way beyond them both. For example, as the true owner of the palantir he was able to contend looking into it versus Sauron himself.
But even removing Aragorn's special insight, from a tactical standpoint, in terms of judgement, Aragorn agreed with Gandalf and differed with Saruman not because he was Gandalf's friend or politics but the opposite. In reality Saruman was wrong, Denethor was wrong. Their strats and their plots were destined to failure. Aragorn and Gandalf were on the same page and became friends BECAUSE they understood correctly what had to be done, it is not that they agreed because they were having a friend's back in an argument.
Gandalf was always preaching proactive action, before Sauron built his strength. Saruman was always contending against action. So obviously striking early was the right tactic and so obviously Aragorn would have advocated that and supported all who also advocated the correct strat. Saruman hoped to contend with Sauron for power, to delay and delay and once the contenders had all battled themselves out to use the ring to overthrow Sauron to create a great new world as Saruman envisioned. This was the wrong tactic, it could have never worked, and so obviously Aragorn would have seen very early that Saruman, for whatever reason was not in it to win it, and with Gondor as his main priority Aragorn would have seen what a massive danger this course of action would have provided.
In this section, Tolkien writes that Aragorn and Denethor... alike almost like kin in appearance, nobility, strength and intelligence... agreed on everything they advised the Steward except Saruman. This makes sense because Denethor was a masterful man one of the best in Middle Earth of the era. He was a future Steward and had a large amount of the Numenorean pureblood DNA. And Denethor had Gondor's best interest at heart. But the only thingd where he failed is in 2 areas. First he could not win the hearts of men, and the people of Gondor like Aragorn naturally did (as the rightful King and their destined leader). and in this most important question of Sauron and the matter of the Ring, he lacked the very elite level of insight of the proper course of action... compared to Aragorn, the Heir to Isuldir and the rightful King. Keep in mind that this was a question that almost no one could master... including all of the Wise, and the Elven council. Only the rightful King, the final White Wizard, the Ringbearers and Galadriel had the "virtue" and the nobility to understand the mission. this again shows the separation from the Rightful King, and the pretender, no matter how noble and well-intentioned he might be
Finally, from a literary standpoint, that sentence even from a stylistic standpoint sets up Aragorn and Gandalf as foils, against Denethor and Saruman. It is a chance to link the sort of virtue and plain right-thinking of the 2 heroes versus the 2 tragic and misguided figures.