The expression has in origins in the medical profession. Doctors in Britain were not permitted to work on dead bodies until an Act of Parliament permitting them to do so was passed in 1832. Prior to this date the only bodies they could dissect for medical purposes were those of executed criminals. Although the execution of criminals was far from rare in 18th century Britain, it was very unlikely that a doctor would come across many corpses during his working life. It was therefore common practice for a doctor who had the good fortune to dissect the corpse of an executed criminal to keep the skeleton for research purposes. Public opinion would not permit doctors to keep skeletons on open view in their surgeries so they had to hide them. Even if they couldn’t actually see them, most people suspected that doctors kept skeletons somewhere and the most logical place was the cupboard. The expression has now moved on from its literal sense!