A slang phrase coined by Thomas A. Dorgan. The phrase became popular in the U.S. in the 1920s, along with the bee's knees, the cat's whiskers (possibly from the use of these in radio crystal sets). In the 1920s the word cat was used as a term to describe the unconventional flappers from the jazz era. This was combined with the word pyjamas (a relatively new women's fashion in the 1920s ) to form a phrase used to describe something that is the best at what it does, thus making it highly sought and desirable.
A report in the New York Times of a publicity stunt by an unknown woman in 1922, in which she paraded along 5th Avenue clad in yellow silk pajamas and accompanied by four cats similarly dressed, may indicate the phrase was already current by that date, as the "cat's meow" certainly was.