What is the "bin" in "loony bin"?
A bin is an enclosed place for storage, such as a coal bin.
From Merriam-Webster:
Etymology:Middle English binne, from Old English binn, binne manger, basket, probably of Celtic origin; akin to Gaulish benna two-wheeled cart with a wicker body; akin to Greek phatn* manger, Old English bindan to bind * more at BIND
: a box, frame, crib, or enclosed place used for storage coal bin *apple bin* grain bin
The OED says the receptacle meaning is used "in the most diverse senses" and gives examples storing grain, straw on a farm-yard, a partition in a barn, manger for animals in a barn, and a receptacle for storage of food ("corn, meal, bread, fruit") and later other things like dust and coal.
Interestingly, the following was only added to the OED as a draft addition in 1997 and first quoted in 1972:
Any receptacle for holding rubbish or waste, esp. waste paper; a waste-bin.
1972 T. Stoppard Jumpers i. 23 Crouch enters from the Kitchen, carrying a bin of rubbish and several empty champagne bottles.