on Writers Who Kill:
“One morning, I shot an elephant in my pajamas. How he got into my pajamas I’ll never know.” Groucho Marx was clever at turning ambiguities in the English language into jokes.
The humor comes from his interpretation of the sentence in an unexpected, but certainly grammatically supported, manner.
Sometimes the meanings of such sentences are not quite so clear.