My answer will be on Late Medieval-Early Modern times and mainly in England. In particular my field of knowledge is more in the Early Modern. But I hope to give you a general enough answer, and a lot of the Early Modern is more or less true of the Late Medieval and there is a blurred temporal boundary between them (somewhere in the 15th century).
There are multiple ways in which a Medieval or Early Modern person might encounter knowledge on this topic, or at least what was perceived to be knowledge as some of this was outright false. Firstly, parents, tutors and formal schooling. Secondly, specialist medical training and experience. Thirdly, midwifery, a female variation on physicians and surgeons which was more heavily experiential.
On the first, medical and scientific knowledge was not a major part of the humanistic curriculum typically used. Eucharius Rösslin, a German physician wrote a book called Der Swangern Frauwen und Hebammen Rosegarten (Rosegarden for Pregnant Women and Midwives) which is a lovely euphemism, was translated into English as The Birth of Mankind, otherwise named the Woman's book in 1540 and another edition in 1545. It became on one of the most popular books available by print to the public. It was also one of the first vernacular (written in English) English books on the subject. Any family who could afford it might have it, and it would have been an influence on the male and female medical professionals as well. Like Medieval Latin predecessors, it was built substantially on humours and on the idea of women as imperfect men who had inverted penises. For the education and amusement of its readers, it also provided rather graphic drawings of anatomy, including the supposed penis that formed the structure of a vagina. Medical sex-ed was relatively limited, but one thing very uniform and essential in the society was the teaching of social sex ed, which had economic and potentially political implications.
As an example I will use “Lord Burghley's ‘Ten precepts’ for his son, Robert Cecil: a new date and interpretation”, by Fred B. Tromly (2015). During the 1580's, Elizabeth I's chief minister William Cecil wrote a document for his son attended to advise him. Tromly argues the document was later than previously thought, and that it's primary concern was the attainment of paterfamilias, to be an established adult man with a household. Typically, one of the concerns in the document is to marry judiciously. This carried special weight not only because Robert was functional heir to the most powerful English family, but because he was an unconventional person to be in that position. Their family was not very well-born, as relatively minor gentry or Welsh descent who had gained minor significance to in service to the Tudors. Furthermore, Robert Cecil was congenitally deformed in some way. There was enough of a sense of heredity that Burghley advised him not to marry a "cripple" with whom he "mayest beget a race of pygmies". Here the primary familial concerns of this kind of advise blurs with the medical angle, because physical features, especially hereditary ones were part of this consideration. In a similar way, mothers appear to have been expected to give their daughters "the talk', as it were, about periods and their own advice around marital and familial practicalities.
For those actually studying medicine, their knowledge of sexual affairs would be affected by discipline. Physicians primarily dealt with more chemical matters, humours were the centre of physic and testing health was primarily done through liquid measures particularly urine. The physician holding a urinal jar up to the light by the patient's bedside was the archetypal image of healthcare. Surgeons were less prestigious because the body was more unseemly than the humours, yes; piss was more prestigious than surgery. The body was increasingly less connected to the divine element over the course of the Late Medieval and Early Modern period in favours of the humours as the seat of the spirit ("Determinants of the revival of dissection of the human body in the Middle Ages", P. Prioreschi, 2001). The most prestigious surgeons were those from the Fellowship of Surgeons many of whom were university trained, and some of whom practised both physic and surgery which would have given them more credit. On the average level though, you were quite likely to deal with barber-surgeons who were officially members of the Barber's Company but some of whom practised largely surgery. They had their own training programs of seven-nine years apprenticeship to a master surgeon in the company. Finally there are apothecaries, first seen in the Guild of Pepperers formed in London in 1180, also the Grocer's Company and later given the prestigious recognition of a livery company as the Worshipful Society of Apothecaries, founded in 1617. Apothecaries were slightly less formal than physicians, and were more akin to pharmacists and indeed with less academic qualifications than today. Unlike medical doctors, women could be apothecaries although they could not get a license from a company to do so. Apothecaries knowledge would have been more handed-down than the physicians, who did the most book-learning of the medical practitioners. All of these people would have some knowledge of sexual affairs and cases involving male potency, pregnancies, STDS and other things might come their way. The surgeons might have the most detailed knowledge of the anatomy, although anatomy was included for physicians as seen in Rösslin's book. But physicians and apothecaries would have more cases involving sexual issues because surgery isn't usually relevant and pregnancies were delivered by women. See "The Royal Doctors, 1485-1714: Medical Personnel at the Tudor and Stuart Courts" by Elizabeth Jane Furdell (2001) and "Surgeons oF the Mary Rose: The practice of surgery in Tudor England" by James Watt (2013).
Speaking of which, we come to midwives. The lines between different practises I think it is clear were blurred, seen in the barber-surgeons and physicians-surgeons. A lot of midwives operate in country towns might also serve as a local apothecary, given that knowledge of plant-based medicine was useful to both and could be obtained by the same passed-down method. Although midwives were not considered medical professionals in the same way, they were given credit and physicians were given limited access to pregnant women during a confinement. The gender norms of the time dictated primarily homosocial interactions, so women had less contact with male doctors than male patients. Midwifes would have learned more mothers and other females relatives in the way of my point on social methods, with the addition of more detail. Girls might be allowed to see their mother's pregnancies in some circumstances, as they were of the correct gender to allow it. Midwives were generally experienced with pregnancy themselves through births, which was one of the most important qualifications at the time.
Lastly as a brief note, the experience of having sex would have served. Which is where premarital sexual behaviour is particularly relevant, more tolerated from men than women and more tolerate in rural than urban settings. The premarital tolerance for men also extended to a certain degree of tolerance of same-sex sexuality, as long as it was limited, conformed to standards of propriety and ended with marriage. You might still get some judgement from this, especially from the priests and the devout. A dedicated love affair was unambiguously a no-no. But this latitude for affairs of various sorts might help earning some sexual practise.