means to disclose a secret that was supposed to be kept as a secret.
The first origin story claims the phrase refers to the cat o’ nine tails, infamously used by the Royal Navy as an instrument of punishment aboard its ships. The whip’s nine knotted cords could scratch an undisciplined sailor’s back pretty badly, hence its feline nickname. The bag comes into play because the “cat,” being made of leather, had to be kept in a sack to protect it from drying out in the salty sea air and keep it flexible. Removing a whip from a sack doesn’t immediately seem to have anything to do with revealing a secret (that the lash was on board the ship and would be readily used shouldn’t have been a secret to any sailor), but if you think of “letting the cat out of the bag” as a revelation that results in a punishment, it makes a little more sense.