He returned from the Citadel just in time to tell Bran about the High Septon’s diary entry that revealed Rhaegar’s annulment of his marriage to Elia Martell and his subsequent marriage to another woman.
Although the woman was not named in the High Septon’s diary, Sam was clearly able to connect the dots once he heard Bran’s side of the story.
Well, Sam was on hand to correct Bran on that particular point.
He even has a king’s name, as Aegon was the name of a number of Targaryen kings, including Aegon the Conqueror who first took the Seven Kingdoms for himself.