This dates back to the days of Reverend William Archibald Spooner (1844–1930), the pastor of New College, Oxford, England, who would stand up in the pulpit and say "The Lord is a shoving leopard" instead of "a loving shepherd," or end a wedding with, "It is kisstomary to cuss the bride."
So linguists call that a Spoonerism, in his honor, defining it as "an error in speech or deliberate play on words in which corresponding consonants, vowels, or morphemes are switched between two words in a phrase."
From what we can read of the Rev. Spooner, he was a very intelligent man whose thoughts sometimes came to him faster than his words could be formed, such as time he found a worshipper in the wrong seat in church ("You are occupewing the wrong pie") or asked to see the Dean of his school ("Is the bean dizzy?").
Just as every statement that seems goofy but has a kernel of wisdom deep within ("If people don't want to come out to the ballpark, how are you gonna stop them?") winds up being attributed to Yogi Berra, every slip o' the tongue seems to get lumped in the dap of the good preacher. Does it matter whether it was he who said, at the end of World War I, "When our boys come home from France, we will have the hags flung out," as long as SOMEONE did?