Yes, he did, because it’s the only way his plan to marry Margaery to Robert makes sense.
He probably figured it out the same way that Varys and LF and Stannis and Jon Arryn did – put two and two together with the hair color, then confirm it by spying on Cersei and Jaime (more the former two than the latter two then). They weren’t very good at hiding their affair.