1580s, "cause to make a weak, sharp, sound" (transitive), of imitative origin (compare Dutch and East Frisian klikken "to click;" Old French clique "tick of a clock"). Intransitive sense "make a weak, sharp sound" is from 1610s.
The figurative sense, in reference usually to persons, "hit it off at once, become friendly upon meeting" is from 1915, perhaps based on the sound of a key in a lock. Mental figurative meaning "to fall into context" is by 1939. Related: Clicked; clicking.