The expression refers to revealing a secret, and Snopes says it originated from “. . .chicanery practiced upon those purchasing livestock.” An unscrupulous seller would swap a cat for a pig that had been purchased. The buyer wouldn’t know he had been duped until he returned home and “let the cat out of the bag.” The expression “Pig in a Poke” was posted earlier, and it had a reference to this expression.