How are STIs different from other pathogens?
STIs are infections of pathogens that either live in the genital area and/or exist in body fluids and also usually don't get transmitted in simpler ways such as airborne particles or contaminated surfaces.
Sexual contact is simply one of the few ways that humans exchange those fluids or have skin contact between the genital areas of two individuals and the by far most common way for the disease to be transmitted.
For example, Staphylococcus aureus bacteria live very happily in the genital regions and could certainly be transmitted sexually, but we don't think of Staph as a sexually transmitted disease because it's found in/on other places too and is also transmitted easily without skin to skin contact.
Where do STIs originate from in the human population?
Bacteria and viruses that today are thought of as sexually transmitted are simply those that have specialized to infecting and spreading in the genital area. Given that there are relatives of those pathogens that have other patterns of infection, and given how evolution operates more broadly speaking, it is straightforward to say that sexually transmitted infections are caused by pathogens that evolved from similar species with other patterns of infection/transmission or other host species.
HIV is a special case in that it's a relatively new STI for humans and its history has been closely studied (see Sharp & Hahn, 2011). Viruses similar to HIV seem to have been in monkeys for a long time, and at some point were transmitted to chimpanzees, probably due to blood contact between chimpanzees and monkeys they were eating, and most likely spread to humans from chimpanzees in the same fashion. Once a human was infected in this fashion, the primary way they spread the infection to other humans was sexually.
Where do STIs originate from in a given person or sexually active couple
Given two people who are not infected with STIs, they cannot spread STIs between them through sexual contact: STIs do not originate spontaneously.
However, someone who currently does not have an STI can in the future become someone who does have an STI and then spread infection to their partner, primarily by sexual contact with some third party who is infected.
It is possible for sexually transmitted pathogens to also be transmitted in other ways; for example, for several STIs transmission is possible during childbirth, herpes viruses can be transmitted by mouth contact, HIV is transmitted by blood contact such as contaminated blood supplies or reused needles in situations of poor medical practice or illicit drug use (or in the patient zero case described above for HIV, through blood contact of another host).
Someone infected in any of these ways can then spread the infection to a sexual partner.
Sharp, P. M., & Hahn, B. H. (2011). Origins of HIV and the AIDS pandemic. Cold Spring Harbor perspectives in medicine, 1(1), a006841. DOI