In medieval England, piglets were sold in the open marketplace. The seller usually kept the pig in a bag, so it would be easier for the buyer to take it home. But shady sellers often tried to trick their buyers by putting a large cat in the bag. If a shrewd shopper looked in the bag - then the cat was literally out of the bag. That is where the expression came from!