TWAG: Based on old movies, it seems that the phrase gained popularity after WWI. I’d guess that returning doughboys might have picked up the habit of using rude words, and when one slipped out in polite company they attempted to cover the faux pas by explaining the word is a French one that just happens to sound like a rude word in English but is actually innocent.
ISTR this being asked before, and I made the same guess. I don’t remember if I was shown to be incorrect.