There have been cases of this happening. If I recall correctly, at least one woman was exonerated by anti-doping after attributing the banned substances to her boyfriend's semen.
Here's an academic paper that does a good job of explaining the risks, etc. while highlighting 3 cases:
Case 1
22‐year‐old female athlete produced a urine sample containing low concentrations of LGD‐4033 (detectable but below minimum required performance limits [MRPL] of 2 ng/ml) and its dihydroxy metabolite (detectable but not qualifiable without reference standard) in A sample with confirmation of detectable metabolite in the B sample. Her boyfriend was taking Ligandrol (LGD‐4033) 12 mg per dose sporadically but about twice weekly including taking multiple doses over the week prior to athlete's test with the last dose 3 days prior to sex with the athlete.
Case 2
21‐year‐old female athlete produced a urine test containing low but detectable concentrations of letrozole metabolite (bis(4‐cyanophenyl) methanol) and GW1516 (GW1516 sulfoxide & GW1516 sulfone). All positives were detectable but below MRPL (20 ng/ml). Her boyfriend was taking oral solutions of Letrozole and GW1516 daily for between 2 to 3 weeks over the period of the athlete's positive urine test when they had frequent sex.
Case 3
20‐year‐old female athlete with multiple negative anti‐doping tests over the previous 2 years produced a urine sample with low concentrations of mesterolone metabolite (1α‐methyl‐5α‐androstan‐3α‐ol‐17‐one) in the A sample and confirmed in the B sample. Boyfriend was taking mesterolone (50 mg daily) with additional 25 mg doses prior to sex.
Drug Test Anal. 2022 Sep; 14(9): 1623–1628.
Published online 2022 Jun 9. doi: 10.1002/dta.3331
Sexually transmitted doping: The impact of urine contamination of semen
David J. Handelsman,corresponding author 1 , 2 Feyrous Bacha, 1 Marsha DeBono, 3 Sue Sleiman, 1 and Margaret R. Janu 3
Abstract
The high sensitivity of antidoping detection tests creates the possibility of inadvertent doping due to an athlete's unknowing ingestion of contaminated environmental sources such as dietary supplements, food, or drinks. Recently, athletes denying use of a prohibited substance have claimed that the positive antidoping tests was due to exchange of bodily fluids with a nonathlete partner using a prohibited substance. Measurement of drugs in semen is largely limited to one or very few samples due to the inaccessibility of sufficiently frequent semen samples for detailed pharmacokinetics. An emerging issue in semen drug measurements is that semen samples may contain residual urine from ejaculation left in the urethra; however, the urine content in semen samples has not been studied. In the present study, we employed concurrent creatinine measurements in urine and seminal plasma to determine the urine content of semen samples.