Since your question is about the interaction between the two Clegane brothers at the truce meeting in season 7, I will limit my answer to only events before and during that meeting. I will leave out events from season 8.
Since you also requested answers from the book series, I will base my answer on the books where I can.
Sandor Clegane probably did not know for certain, but he probably made a very educated guess.
When Eddard Stark first saw Ser Gregor Clegane, it was at the Hand's Tourney. The book gives a memorable description of the man's immense size.
He was huge, the biggest man that Eddard Stark had ever seen. Robert Baratheon and his brothers were all big men, as was the Hound, and back at Winterfell there was a simpleminded stableboy named Hodor who dwarfed them all, but the knight they called the Mountain That Rides would have towered over Hodor. He was well over seven feet tall, closer to eight, with massive shoulders and arms thick as the trunks of small trees. His destrier seemed a pony in between his armored legs, and the lance he carried seemed as small as a broom handle.
~ A Game of Thrones by George R. R. Martin, chapter named Eddard, page 295.
(Side note: A destrier is a type of horse from medieval Europe that was prized for being big and strong enough to hold a knight in full armor. A destrier had strong back legs for running at full gallop while carrying an armored knight. For a man to be so big that the large horse under him would look no bigger than a pony means the man was extremely huge.)
Later when King Robert is out hunting for days and Eddard Stakes sits on the throne giving justice as the King's Hand, several people from the countryside come into the Red Keep describing raiders led by a huge man. The huge man was likely Ser Gregor Clegane hiding his face inside plain armor so no one would know that a Lannister bannermen led the raids against the villages in the Riverlands.
The brewer, Joss, shook his head. "It grieves me m'lord, but no, the armor they showed us was plain ... only the one who led them, he was armored like the rest. But there was no mistaking him all the same. It was the size of him, m'lord. Those as say the giants are all dead never saw this one, I swear. Big as an ox he was, and a voice like stone breaking."
"The Mountain!" ser Marq said loudly. "Can any man doubt it? This was Gregor Clegane's work!"
Grand Maester Pycelle rose ponderously from the council table, his chain of office clinking. "Ser Marq, with respect, you cannot know this outlaw was Ser Gregor. There are many large men in the realm."
"As large as the Mountain that Rides?" Ser Karyl said. "I have never met one."
~ A Game of Thrones by George R. R. Martin, chapter named Eddard, page 466.
From these passages in the first book we learn that although there are many large men in the realm, Gregor Clegane is bigger than any man.
We also know from the books and TV series that Qyburn was expelled from the order of Maesters for experimenting with dead people. We don't know exactly what those experiments were, but we have reason to believe he learned how to re-animate a dead person into a zombie long before Cersei employed him. Cersei deliberately asked Qyburn in the TV series that if Gregor would be just as strong after he was re-animated. Qyburn knew enough to predict that Gregor would retain his strength.
If Cersei were to ask that kind of question, she likely knew the reason about the experiments that led to his expulsion. Why else should she employ him and turn over Gregor's corpse to him?
Let's assume that if Cersei knew about Qyburn's skills at bringing the dead back to life, then surely others did too. It's no small claim to think that Sandor Clegane had heard about Qyburn's past as well.
This is a list of what Sandor Clegane knows when he sees a very tall and very muscular knight guarding Cersei at the truce meeting.
- The armored silent knight is as tall as his brother, Gregor.
- The tall knight was also very muscular. Sandor could easily assume that underneath that armor is a man with arms as thick as small tree trunks.
- No other man in Westeros was known to be that tall and that muscular.
- The man's eyes look creepy as if he was a zombie or some undead unholy monster of a man.
- He knows that Gregor was killed by the younger Martell prince.
- Qyburn is sitting next to Cersei with the pin that indicates he is the Hand of the Queen.
- Sandor Clegane heard of rumors that Qyburn can bring dead people back to life.
When Sandor Clegane puts the facts together, he assumes (correctly) that the tall knight is his undead brother, and that Cersei hired Qyburn to turn his brother into a zombie.