This is a musical interpolation. The term has several related meanings, but this is one of them.
an abrupt change of musical elements... [followed by a] resumption of the main theme.
You can think of it broadly as a song, or a portion of a song, inserted into another, stylistically distinct song. In the case that it never comes back to the original, it is a medley (two or more different songs that transition into each other) or a suite (a series of short musical pieces intended to be played together in order).
A famous example along the lines of the ones you mentioned is the Beatles' "A Day in the Life" which interpolates a cheerful, down-to-earth song by Paul in the middle of John's dreamy reveries. Later, in the 1970s, as progressive rock moved to the forefront, a number of artists produced songs that either had long dramatic instrumental bridges interpolated in the middle, or that featured a relatively brief vocal interpolation inside a longer instrumental piece. These include Frank Zappa's "Willie the Pimp", Neil Young's "Down By the River", the Chambers Brothers' "Time has Come" and Joe Walsh's satirical epic rock classic "Life's Been Good." Pink Floyd's "Shine on You Crazy Diamond" takes this to extreme lengths, with the entire rest of the Wish You Were Here album arguably interpolated inside this extended, multi-part suite.
Also of interest might be Beyonce's recent hit, "Hold Up" which interpolates portions of two other songs and several distinct sections into a single musical collage. This builds from the relatively common modern hip-hop and R&B technique of interpolating resung portions of older songs, as in the Method Man & Mary J. Blige hit "You're All I Need". The same technique of quoting other songs is also found in songs like Moxy Fruvous' "Drinking Song" ("Goodnight Irene"), Tom Waits' "Waltzing Matilda" and the Christian hit "My Chains are Gone" ("Amazing Grace"). Finally, there are also "anthology songs" made up almost entirely of such quotes, such as "Sweet Soul Music" and "Rockollection."