Fact: The scene was never meant to be in the actual film. Joe Pesci acted out the scene to Martin Scorsese. The line was based off of real life events.
Goodfellas (1990) is regarded as one of the best mobster movies of all time. It contained some of the best actors including Robert De Niro, Joe Pesci, Ray Liotta, Paul Sorvino, and Frank Vincent. The film was based off of the real life portrayal of Henry Hill. Henry Hill was an FBI informant whose life was immortalized by the movie (he idolized local mafiosos, such as Paul Vario, a capo in the Luchesse crime family). Hill stated that Joe Pesci’s portrayal of Tommy DeSimone was 90-99% accurate, with one notable exception; ‘the real Tommy DeSimone was a massively built, strapping man.’
The “You Think I’m Funny?” scene was based off of Joe Pesci’s real life when he worked in a restaurant as a young man. Pesci told a mobster that he was funny. From the quote, the mobster wasn’t very happy and became angry. That is how that quote came about. In shooting the scene to which the line would carry life, Scorsese allowed Pesci and Ray Liotta to improvise the scene. He did not tell the other actors in the scene what would happen because he wanted their genuine surprised reactions (IMDB). Scorsese was so anal about the actor’s wardrobe that he tied Ray Liotta’s tie himself to make sure it was accurate for the film’s setting.
During around the time of shooting this scene, Ray Liotta’s mother passes away of cancer. Liotta explains that he uses the anger over losing his mother in specific scenes, like the pistol-whipping scene.