Beliefs about how all babies develop, not just twins, depended on medical-philosophical literature going all the way back to Aristotle, who thought, essentially:
Step 1: Sperm mixes with menstrual blood
Step 2: ???
Step 3: Baby!
Not to be too facetious about it...but they were just guessing until the 17th century. They had no idea at all. They knew about semen and embryos and fetuses, but not sperm, or cells, or eggs...no one knew about those before microscopes were invented. So they tried to figure it out with logic and philosophy. According to Aristotle, since all things are made of “matter”, when there are twins either the mother or father must have contributed too much matter...somehow...
In the Middle Ages,
"One common belief was that multiple births were the result of having intercourse with two or more different men." (Paul B. Newman, Growing Up in the Middle Ages (McFarland & Company, 2007), p. 19)
Newman cites some medieval literature where women are accused of being adulterers because they had twins. But that goes back to Aristotle too: he told the story of Heracles and his twin Iphicles, where their mother Alcmene slept with Zeus and then her husband Amphitryon and was impregnated twice. So ancient and medieval could explain fraternal twins as being the result of adultery, even though they knew that wasn't really true (it could happen, it's called "superfecundation", but it's pretty unlikely). For identical twins that clearly weren't the result of adultery, they just...didn't have a specific explanation.
In philosophical terms, twins were "unnatural" (since women did not usually give birth to twins) and therefore "monsters", but not really in a pejorative sense. They were different, like people with 11 toes or some other unusual physical characteristics, but they were nevertheless rational humans like everyone else.
This is mostly taken from J.M. Thijssen, "Twins as monsters: Albertus Magnus' theory of the generation of twins and its philosophical context" (Bulletin of the History of Medicine 61, p. 237-46). Thijssen was looking at the way the 12th-century philosopher Albertus Magnus expanded on Aristotle's ideas about how the "matter" in semen divides, depending on how men and women are moving and thrusting, and how semen interacts with the uterus once it's in there. Depending on all that, the "matter" would divide into a boy or a girl or the various kinds of twins. It's more the realm of philosophy than science.