If a man has HIV, one of his body fluids where the virus is found is his semen. During sex if his semen gets into the body of his sexual partner then that person could also get infected.
The clear fluid produced by a man’s penis when he is sexually excited ('pre-cum') can also have HIV in it. This is why there remains a risk of infection even if, during sex, a man pulls out of his partner before he ejaculates.
If a woman has HIV, one of her body fluids where the virus is found is in her vaginal secretions. During sex if these come into contact with man’s penis than HIV could be transmitted to him.
Using a condom correctly prevents contact with semen or vaginal secretions, stopping HIV from passed on.
If a man or woman are taking HIV medication, the amount of HIV in his semen or her vaginal secretions should fall a great deal, making these fluids potentially less infectious. But it is still possible for infections to happen even if someone is on HIV drugs and they have with a low or undetectable viral load. It would be wrong to think that unprotected sex with them is totally risk-free.
If a man with HIV gets a sexually transmitted infection there can also be a rise in the amount of HIV in his semen.