I think the best way to explain this is to quote Wikipedia.
The passage in Genesis 1:27 — "So God created man in his own image, in the image of God created he him; male and female created he them" (before describing a mate being made of Adam's rib and being called Eve in Genesis 2:22) is sometimes believed to be an indication that Adam had a wife before Eve.
A medieval reference to Lilith as the first wife of Adam is the anonymous The Alphabet of Ben-Sira, written sometime between the 8th and 11th centuries. Lilith is described as refusing to assume a subservient role to Adam during sexual intercourse and so deserting him ("She said, 'I will not lie below,' and he said, 'I will not lie beneath you, but only on top. For you are fit only to be in the bottom position, while I am to be the superior one.'"). Lilith promptly uttered the name of God, took to the air, and left the Garden, settling on the Red Sea coast. As a side note, this places Lilith in a unique position, for she left the Garden of her own accord and before the Fall of Man, and so is untouched by the Tree of Knowledge. However, she also knows the true name of God, which makes her even more powerful.
Lilith then went on to mate with Asmodai and various other demons she found beside the Red Sea, creating countless lilin. Adam urged God to bring Lilith back, so three angels were dispatched after her. When the angels, Senoy, Sansenoy, and Semangelof, made threats to kill one hundred of Lilith's demonic children for each day she stayed away, she countered that she would prey eternally upon the descendants of Adam and Eve, who could be saved only by invoking the names of the three angels. She did not return to Adam.
The background and purpose of The Alphabet of Ben-Sira is unclear. It is a collection of stories about heroes of the Bible and Talmud, it may have been a collection of folk-tales, a refutation of Christian, Karaite, or other separatist movements; its content seems so offensive to contemporary Jews that it was even suggested that it could be an anti-Jewish satire [3], although, in any case, the text was accepted by the Jewish mystics of medieval Germany.
The Alphabet of Ben-Sira is the earliest surviving source of the story, and the conception that Lilith was Adam's first wife became only widely known with the 17th century Lexicon Talmudicum of Johannes Buxtorf.
In the late 19th century, the Scottish Christian author George MacDonald incorporated the story of Lilith as Adam's first wife and predator of Eve's children into a mythopoeic fantasy novel in the Romantic style.