It goes way back. Dave Fleischer’s “Out of the Inkwell” cartoons had the cartoon characters interacting with reality all the time (no celebrities, though). This was in 1918,
You can also credit “Gertie the Dinosaur,” usually considered the first animated cartoon. Creator Windsor McKay used to show it in his lectures, and toss a ball to Gertie.
In “You Ought to Be in Pictures” (1940), Porky Pig goes to his boss Leon Schlesinger to quit his job. Schlesinger (the producer of Looney Tunes and Merrie Melodies) appeared live in the short.
In on of Annie Hall’s best gags, Woody Allen pulls Marshall McLuhan out of nowhere to tell a bore that he had gotten McLuhan’s philosophy completely wrong. Allen also had Howard Cosell playing himself in Bananas.
In a Dr. Who episode, “The Chase,” the Beatles are shown performing “Ticket to Ride,” which is called “classical music” by Vicki, who came from Earth’s future. Other historical figures are also shown (Shakespeare, Queen Elizabeth I). H. G. Wells shows up in another episode of the series (to say which one would be a spoiler).
Daniel J. Travanti once showed up as a guest of the Inn on Newhart as himself.
Jennifer Grey played herself in It’s Like, You Know in a regular role.
The Simpsons was filled with real people showing up in Springfield. These included Leonard Nimoy, The Who, the Red Hot Chili Peppers, Spinal Tap, Paul and Linda McCartney, George Harrison, and George Bush.
Similarly, Adam West has a recurring part in Family Guy as the mayor.
Nancy Reagan showed up on Webster.
Donald Trump shows up all over the place (The Little Rascals, Drew Carrey, 54, Celebrity, etc.). Ivana Trump showed up in The First Wives Club.