This seems like it should be straightforward, but I don't know how to do it, so it's not for me at least. At the timestamp I provide in this song, the Animaniacs' Presidents Song, there is a quote from Dixieland as a joke. This quote feels natural and like it should be there. At those first two notes, you can't even tell that they're about to sing Dixieland rather than the melody that they've been singing up to this point. How do you do that? I'm a rock/electronica musician, so in my case I'd find information geared toward popular-style music rather than art music more useful. I can't think of other examples off the top of my head and search engines don't necessarily search for stings in the middle of songs, so to clarify, I mean that thing in music where one quotes a motif as a one-off "joke" or reference, especially to underscore some lyric ("Those dweebs with cellos" with BWV 1007 briefly heard).
Short answer - you just do it! You write some notes that are recognisable as one tune, then you write some that are recognisable as another. If you're feeling clever you can sometimes even intertwine them!
The whole song's a parody of Rossini's 'William Tell' overture. The last two notes of of 'William Tell' are the same as the first two notes of 'Dixie', allowing a witty overlap of the two tunes. The quote from 'Mademoiselle from Armentières' at 2'19" is rather less subtly inserted, plus a few bars of marching drums. At 2'42" there's a couple of extra beats inserted to give us a chance to register the sound effect of Roosevelt's flying wheelchair! There's a similar insertion of Ford's 'falling down' sound at 2'56".
And that's how you do it. You tell the musicians to play those notes at those times and record them. Bit harder if you're building a sound collage from existing material! But these guys weren't doing that.
I suppose we should be grateful it ends with Clinton :-)
These musical jokes are sometimes called "musical puns" - inserting fragments of other works whose spirit or title relates to the action on screen. This Animaniacs clip in particular reminds me of the music Carl Stalling wrote for the old Looney Tunes cartoons. These quotations are actually rather simple to include - you just put it in. The structure of the song stops for a few measures, while the quotation plays, then the song picks up where it left off.
There is another kind of musical quotation in which the structure of the song continues unabated. This technique requires that the quotation more-or-less follows the chord structure of your song, and you need to transpose the quotation into the correct key. This is a technique often employed by jazz musicians during their improvisations.
Here are a few examples of quotations in pop music:
All You Need is Love by The Beatles The piece starts with fanfare quoting "La Marseillaise" (the French national anthem), which is sort of in the first style. Then, while the band plays the ending vamp (around 3:05), the saxophones play the intro of Glenn Miller's "In the Mood," which was originally recorded in Ab but is transposed to G to fit the harmony. Then (around 3:13) the strings play Greensleeves. Neither of these last two quotations really line up with meter of the song, but the song keeps going on anyway, so the effect is kind of chaotic.
I Believe in Father Christmas by Greg Lake This Christmas song includes a melody from 20th century Russian composer Sergei Prokofiev - the Troika section of Lieutenant Kijé. This quotation has a slightly different function because it is used repeatedly, like a refrain or chorus; in that way, it is a bit like how a hip hop producer might use sample to create a hook.