An exclamation of surprise, similar to ‘heavens to Betsy.’
This American phrase dates from the mid 20th century and was popularized by the cartoon character Snagglepuss – a regular on the Yogi Bear Show in the 1960s.
The first known use of the phrase, however, comes before that, from the 1944 film Meet the People. It was spoken by Bert Lahr, best remembered for his role as the Cowardly Lion in The Wizard of Oz. Snagglepuss’s voice was patterned on Lahr’s, along with the ‘heavens to Murgatroyd’ line.
As with Betsy, we have no idea who Murgatroyd was. While it is doubtful that the writers of Meet The People were referring to an actual person, they must have got the name from somewhere. Perhaps from Gilbert and Sullivan’s comic opera Ruddigore, 1887, where ten of the characters in are baronets surnamed “Murgatroyd,” though eight are ghosts.
Murgatroyd has a long history as a family name in the English aristocracy, however. In his genealogy The Murgatroyds of Murgatroyd, Bill Murgatroyd states that, in 1371, a constable was appointed for the district of Warley in Yorkshire. He adopted the name of Johanus de Morgateroyde – literally John of Moor Gate Royde or ‘the district leading to the moor.’
As for why the phrase was used in Meet the People, my guess would be that has a nice rhythm and, because the name is unusual, it is more colorful and catches our attention.