The noun marble, denoting a hard crystalline metamorphic rock resulting from the recrystallization of a limestone, is from Anglo-Norman forms such as marbre and marbelle, and from Old-French forms such as marbre, maubre and mabre, from classical Latin marmor.
This Latin noun is from ancient Greek μάρμαρος (= mármaros), shining stone, marble, of uncertain origin, but popularly related to μαρμάρεος (= marmáreos), flashing, gleaming, and μαρμαίρειν (= marmaírein), to sparkle.
French marbre shows unusual dissimilation of m–m, while English marble shows dissimilation of r–r, as does pilgrim, from Latin peregrinus (cf. English peregrine).
A marble is a little ball made originally of marble and now usually of glass, porcelain, baked clay, etc., used in a children’s game. In the classic game of marbles, the players take turns at shooting their own marble, with finger and thumb, at marbles inside a ring, trying to knock the marbles out of the ring to win them.
In the late 19th century, the discomfiture of a boy who has lost his marbles seems to have been to a certain extent proverbial in American English. For instance, the following is from The Daily Shreveport Times (Shreveport, Louisiana) of 28th March 1876:
We scarcely know how to characterise the production of Mr. Wheelock, President of the New Orleans and Pacific Railroad Company […]. It sounds like the passionate ravings of a school boy who has lost his marbles at a game of “keeps,” and wishes to charge his schoolfellows with putting up a job and cheating him.
Another example is from The Use of Double Negatives in English, published in The Hickory Press (Hickory, North Carolina) of 7th January 1897:
In colloquial use, a large per cent. use double negatives where one should be used, yet are rarely misunderstood. Who can mistake the meaning of the boy when he had lost his marbles playing “keeps”: “You needn’t say nothing no more to me about no marbles.”
This is most probably why the plural marbles came to be figuratively used to mean mental faculties, common sense, in the phrases to lose one’s marbles, to have (or not have) all one’s marbles, and variants.
The earliest instance of this figurative usage that I have found is from the Daily Charlotte Observer (Charlotte, North Carolina) of 19th July 1895; a reporter wrote that, during a baseball match between the Quicksteps of Charlotte and the Blue Shirts of Greensboro:
Umpire Harrill lost his marbles in the eighth inning and called five balls on one man before giving him his base.
Another early instance is from the Indianapolis Morning Star (Indianapolis, Indian) of 1st June 1907. An article reported that the question raised in court the day before was whether George Rhodius, “the dissipated Indianapolis millionaire”, was insane. A woman named Elma Dare had allegedly kidnapped him and taken him to Louisville, where they got married. Jesse Stodghill, the hackman who drove the carriage in which Dare and Rhodius went to the train station on the night they left Indianapolis for Louisville thus testified:
“He [= Rhodius] looked to me like a man who didn’t have all his marbles with him.”
The Chicago Daily Tribune (Chicago, Illinois) of 28th January 1952 published this article about the American cartoonist Bill Holman (1903-87):
SMOKEY STOVER ARTIST’S A PUN AND INK GENIUS
Holman Delights in Zany Gags; Fans Do, Too
BY LESLIE MONYPENNY
Any hasty observer might conclude that Bill Holman is shy some of his marbles.
Actually he is a stable and talented fellow with a genius for finding the delightful daffy. Holman is the chap who dreams up the goofy adventures of Smokey Stover in The Sunday Tribune and Nuts and Jolts, a similarly wacky panel in the daily Tribune.
“They’re our daughter’s doll dishes—all the food we can afford to buy these days will fit easily on them.”
cartoon by Bill Holman, published in the Chicago Daily Tribune – 28th January 1952