Only some viruses work this way, HIV is an example. This is a good article on endogenous retroviruses [1], that is viruses that work by integrating themselves into host DNA (a retrovirus) and made it into germline cells (eggs and sperm, the endogenous part).
[1] https://www.bbc.com/future/article/20230519-the-viruses-that...