When Stephen Hawking appeared on The Big Bang Theory, this cameo paid off a joke from the show's pilot.
What made Hawking's appearance such a clever surprise in season 5 was that this cameo paid off a set-up from The Big Bang Theory's pilot. In the show's first episode, Howard imitated Hawking in an off-color joke. While The Big Bang Theory's Howard got better when he began dating Bernadette, he was originally a pretty mean-spirited figure. However, this joke seemed a lot less mean when Hawking himself bore witness to Howard's actor Simon Helberg doing the impersonation in real life and smiled.
As such, Helberg insisted that The Big Bang Theory's producers cleared the scene with Hawking beforehand. However, this caution turned out to be unnecessary as Hawking smiled while watching Helberg perform the risky gag. Helberg was relieved to discover that the late Hawking found the moment funny, thus allowing The Big Bang Theory to pay off a gag that was set up five seasons earlier. While there were plenty of other, more unexpected cameos in the series, like Raj's doomed romance with The Big Bang Theory's Siri, Hawking's appearance was a rare opportunity for the show to get a guest star in on the joke years after mentioning them.
Helberg first did his impression of Hawking in The Big Bang Theory pilot, but that was long before the show's creators could have dreamed that Hawking would appear in the series. As The Big Bang Theory grew in popularity, the chances of Hawking making an appearance in the series improved. As such, The Big Bang Theory's writers could have simply ignored Howard's earlier joke and leaned into Sheldon's fawning over Hawking. However, reminding viewers of Helberg's impression gave Hawking a chance to display his self-effacing sense of humor, turning an already-solid cameo into one of The Big Bang Theory's best guess appearances.