To expand on what Silver Dragon said, Denethor knew Isildur's heir was coming to Gondor to claim the Kingship -- probably via the palantir. In the Pyre of Denethor, after Denethor reveals he's been peeking into the palantir, he says:
Quote:
Do I not know thee, Mithrandir? Thy hope is to rule in my stead, to stand behind every throne, north, south, or west. ... So! With the left hand thou wouldst use me ... as a shield against Mordor, and with the right bring up this Ranger of the North to supplant me. ... I will not step down to be the dotard chamberlain of an upstart. Even were his claim proved to me, still he comes but of the line of Isildur. I will not bow to such a one, last of a ragged house long bereft of lordship and dignity.
|
Even though he doesn't explicitly say he knows Aragorn is Thorongil, this is implied in Appendix A:
Quote:
Therefore, later, when all was made clear, many believed that Denethor ... had discovered who this stranger Thorongil in truth was, and suspected that he and Mithrandir designed to supplant him.
|
So, even though Denethor was dead by the time Aragorn entered Minas Tirith, Denethor had "recognized" him.
I think Theoden probably didn't recognize Aragorn for the reasons already stated. .... Plus, he just wasn't as with it as Denethor.
-Lily