None of the real historical figures included in Forest Gump were “inserted” into the film. Instead, Tom Hanks, as Forrest, was inserted into archival footage of them.
In the case of John Lennon, Hanks was digitally composited into footage from the September 11th, 1971 episode of The Dick Cavett Show. The digital effects team edited out Yoko Ono, the actual guest sitting next to Lennon during that episode, and then superimposed footage of Hanks into the scene in the place she was sitting.
The effects team also needed to make the composited footage of Hanks match the low resolution and grainy footage from the show. This required overlaying the grain themselves and tinkering with the resolution until the “modern” footage of Hanks matched the earlier archival material.
Then voice actors were brought in to imitate Cavett and Lennon so that their dialogue would match Hanks’ dialogue as Gump. This audio track replaced the actual conversation from the original episode.
This is essentially what happened in every scene where Forrest Gump is inserted into footage of an actual historical figure – with the caveat that some of the footage of Hanks also needed to be greyscaled so that it would appear in black and white.
(The same process was used in this scene with JFK, with the composited footage of Hanks greyscaled to fit the black and white footage of Kennedy.)