Genetics was discovered in the 19th and 20th centuries.
Half of an organism's genes come from its male parent and half from its female parent.
Various genes can be good or bad for someone's health. If a gene is dominant, it will be expressed and effective if someone gets it only one parent. If a gene is recessive, it will be expressed and effective if someone gets it from both parents but it will not be expressed or effective if someone gets it from only one parent.
If someone gets one or two copies of a bad dominant gene, they will suffer. If someone gets one copy of a bad recessive gene, it will not affect them. If they get two copies of a bade recessive gene, one from each parent, they will suffer.
The more closely people are related, the more genes they have in common. That includes bad recessive genes. So if someone's parents are closely related, they are more likely to get two copies each of bad recessive genes and suffer from them.
Of course human genetics was not understood until the 19th and 20th centuries.
In ancient and medieval times, there was a medical theory that all of a person's genes came from the father, despite the fact that many children did not outwardly resemble their fathers but did resemble their mother's. It was also believed that it was possible for two or more men to contribute genes to a child if they had sex with the mother at about the same time.
According to legend Merovech or Meroveus, a 5th century Frankish king, was the son of the wife of King Clodio and a river giant in the form of a bull who raped her. And yet some royal families traced their ancestry back to the royal family of Troy though Meroveus, despite the fact that Meroveus's father would have been 100 percent river giant. According to medieval ideas, Meroveus would have been half human because half his genes came from the river giant and half from king Clodio. While modern people (if they believed the story) would say that Meroveus was half human because half his genes came from Clodio's human wife and half from the river giant.
So there wasn't a very strong knowledge of genetics in the Middle Ages in Europe.
There is a natural tendency in humans to not be sexually attracted to people that they have been raised from childhood with. And that could have arisen through natural selection. People who didn't to have sex with their siblings would have children a little less likely to inherit bad recessive genes from both parents and so those children would be a little more likely to survive long enough to have children of there own.
So over thousands of generations humans evolved a repugnance and reluctance to have sex with their siblings.
And that might possibly be all the biological basis for incest taboos. It is possible that all other ideas of what relationships would be incestuous are purely cultural and based on various cultural trends.
I think that according to biology, relationships closer than 2nd cousins have an increased probability of inheriting bad genes, while relationships between 2nd cousins do not increase the probability of inheriting bad genes.
And many societies have been okay with marriages between first cousins, and other societies have prohibited much more distant relationships.
Christian clergymen gained a lot of control over marriage in Christian society. They gradually made it more and more against the rules for illegitimate children to inherit property, and gained more and more control about who would allowed to marry who.
And of course different medieval Christian sects had different rules on which relationships were incestuous and thus forbidden.
The Roman Catholic Church in western and central Europe gradually prohibited marriages between people who were more and more distantly related. If two persons within the prohibited degrees wished to marry, they had to get (and pay for) a dispensation, which specified each and every one of the prohibited relationship they had.
And I think that it was a custom for kings and nobles not to mention one of their prohibited degrees of relationship when applying for a dispensation. So if they wanted to get out of a marriage, they could suddenly "discover" that prohibited relationship decreed null and void - paying a fee, of course.
I once read that about 990 King Hugh Capet of France sent a letter to the eastern Roman or 'Byzantine" emperor, requesting an imperial daughter as a bride for his son king Robert II, and said that he want the daughter of a monarch to be his son's wife but couldn't find any that were not related too closely to Robert.
And that was a problem in Catholic Europe in the Middle Ages. The number of kingdoms, and thus the number of kings who had available daughters, was small.
A number of kingdoms were created and destroyed during the Middle Ages, and it was common for two or more kingdoms to be inherited by a single man. And sometime if a king had two or more kingdoms his sons divide them after he died.
So the total number of separate Catholic royal families on the mainland of Europe and islands in the Mediterranean, plus the 3 Scandinavian kingdoms, and the Kingdoms of England and Scotland in the British Isles, was about 10 to 15 during the Middle Ages. Political changes during the 19th and 20th centuries resulted in the number of European monarchies increasing to over 20 and then dropping to 7 kingdoms, 2 principalities, and 1 grand duchy.
There were a number of other Catholic kingdoms in Medieval Europe. There were a few Kingdoms in Wales, and about 50 to 200 little kingdoms in Ireland. But apparently they were outside of the potential marriage market for the other Catholic monarchs in Medieval Europe.
So as a result, I guess that about half the kings in Medieval Europe married the daughters of other kings, and about half married the daughters of powerful nobles like dukes and counts. During the Renaissance, European royalty started to exclusively marry European royalty instead of nobles, and became a closed caste. But that was only possible because the powerful princely families in the Holy Roman Empire were considered to be equal to royalty for marriage purposes, while other nobles were not.