late Old English cæppe "hood, head-covering, cape," a general Germanic borrowing (compare Old Frisian and Middle Dutch kappe, Old High German chappa) from Late Latin cappa "a cape, hooded cloak" (source of Spanish capa, Old North French cape, French chape), a word of uncertain origin. Possibly a shortened from capitulare "headdress," from Latin caput "head" (from PIE root *kaput- "head").
The Late Latin word apparently originally meant "a woman's head-covering," but the sense was transferred to "hood of a cloak," then to "cloak" itself, though the various senses co-existed. Old English took in two forms of the Late Latin word, one meaning "head-covering," the other "ecclesiastical dress" (see cape (n.1)). In most Romance languages, a diminutive of Late Latin cappa has become the usual word for "head-covering" (such as French chapeau).
Meaning "soft, small, close-fitted head covering" in English is from early 13c., originally for women; extended to men late 14c. Extended to cap-like coverings on the ends of anything (such as hubcap) from mid-15c. Meaning "contraceptive device" is first recorded 1916.
Meaning "cap-shaped piece of copper lined with gunpowder and used to ignite a firearm" is by 1825, hence cap-gun (1855); extended to paper version used in toy pistols, 1872 (cap-pistol is from 1879).
Figurative thinking cap is from 1839 (considering cap is 1650s). Cap and bells (1781) was the insignia of a fool; cap and gown (1732) of a scholar. To set one's cap at or for (1773) means "use measures to gain the regard or affection of," usually in reference to a woman seeking a man's courtship.
The capping of Latin verses is a common game in classical schools. No verse may be used twice, and no hesitation or delay is permitted; so that a moderate proficiency in the game supposes several thousand verses arranged in the memory alphabetically. [Century Dictionary, 1895]