From Wiki Answers:
The word ‘marbles’ has had many meanings throughout history. Marbles are generally known as the little glass balls that children use to play a game. From the mid 19th century, ‘marbles’ was also used to mean ‘personal effects’, ‘goods’, or more generally ‘stuff’. This derived from the French word ‘meubles’, which means ‘furniture’. Therefore, to lose one’s marbles means “to lose your stuff,” or, idomatically, to lose one’s mind.
From World Wide Words:
The earliest example given in the standard references is from It’s Up to You; A Story of Domestic Bliss, by George V Hobart, dated 1902: “I see-sawed back and forth between Clara J. and the smoke-holder like a man who is shy some of his marbles.”
That certainly sounds like the modern meaning of marbles, which as you say refers to one’s sanity. But in an earlier appearance, the writer used it to mean angry, not insane (mad, that is, in the common US sense rather than the British one). It was printed in theLima News of Ohio in July 1898: “He picked up the Right Honorable Mr Hughes on a technicality, and although that gentleman is reverential in appearance as Father Abraham and as patient as Job, he had, to use an expression of the street, lost his ‘marbles’ most beautifully and stomped on the irascible Harmon, very much à la Bull in the china shop.”
The origin must surely come from the boys’ game of marbles, which was very common at the time. To play was always to run the risk of losing all one’s marbles and the result might easily be anger, frustration, and despair. That would account for the 1898 example and it’s hardly a step from there to the wider meaning of mad — to do something senseless or stupid.
Lastly, from Urban Dictionary:
Lose your marbles = lose one’s mind, insanity, person who does not have common sense/wits.“Lose your marbles”
I knew she’d eventually lose her marbles = I knew she’d eventually lose her common sense/rational mind
Have you lost your marbles?. Means the same as “Have you lost your mind”?
There you have it. Have I ever lost my marbles? Absolutely!! Have I found them?? I think the better question is do I want them back!