Also,slip a gear or one's gears. Lose one's ability to reason soundly or make correct judgments, as in She must have slipped a cog or she would never have gone out barefoot in December, or What's the matter with him? Has he slipped his gears? These slangy usages allude to a mechanical failure owing to the cog of a gear or a gear failing to mesh. The first dates from about 1930, the variant from the 1960s.
In addition to the idiom beginning with cog also see:slip a cog