Origin of "chemistry" in reference to that between two people
Solution 1:
Etymonline tells us about this sense of chemistry:
c.1600, "alchemy" (see chemical); the meaning "natural physical process" is 1640s, and the scientific study not so called until 1788. The figurative sense of "instinctual attraction or affinity" is attested slightly earlier, from the alchemical sense.
Alchemy was chemistry in its infancy, and might refer to something that seemed to be magic. These definitions are pertinent:
The causing of any sort of mysterious sudden transmutation.
Any elaborate transformation process or algorithm.
Chemistry between two people is an unexplained reaction, and it came first, before our understanding of the science of chemistry.
Solution 2:
The OED describes this use under definition 3:
Mysterious agency or change, such as that produced by alchemy; (in later use) specifically instinctual attraction or rapport between two or more people.
The earliest recorded figurative use is dated 1656. The earliest clear application to people comes in George Eliot’s ‘Daniel Deronda’, published in 1876:
We mortals have a strange spiritual chemistry going on within us.
Solution 3:
The word 'chemistry' is of Greek origin and describes the reactions various elements have when they meet each other. The undetermined or unexplained reactions between people when they first meet are described with the same word.