I always understood it to refer to the cat o' nine tails - the ship used to instill discipline on the sailing ships of Nelson's navy. The 'cat' was kept in a bag tied to the mast in full view of the men as they went about their work, as a deterrent. To 'let the cat out of the bag' meant that a flogging was to take place, and this was usually witnessed as a further example of punishment.
The old classic "not enough room to swing a cat" comes from the cat o' nine tails in that most ships didnt have enought room to swing the cat o' nine tails bellow deck and therefore did this above deck.