How do DNA viruses keep themselves in the nucleus without inserting themselves into genome?
Herpesviruses maintain themselves during the latent state as "episomes", circular DNA elements, with no capsid, that are in the nucleus but that are not integrated into the host genome. Host enzymes replicate these episomes, and different viruses have evolved different strategies for ensuring that the episomes are passed on to newly-divided cells.


  After they first infect cells, many herpesviruses establish a latent lifecycle with the viral genome existing as circular genetic elements called episomes inside the host cell’s nucleus that are closely associated with, but not integrated into, the host DNA. During latent infection, episomes are replicated during S phase, but new viral particles are not produced and the infected cell survives. The maintenance of herpesvirus genomes as episomes contrasts significantly with retroviruses, which insert their genome within the host cell genome to ensure their replication and inheritance by daughter cells and establish long-term infection. ... EBV uses a mechanism to tether the EBV genome to host DNA, facilitating the equal distribution of episomes in daughter cells with a larger number of cells having at least one EBV genome. In contrast, KSHV uses a clustering strategy that promotes a higher number of episomes per cell, but at the expense of not passing on the episome to some daughter cells


--How herpesviruses pass on their genomes

Another mechanism many herpesviruses use is to establish their latent infection in non-dividing cells, especially neurons, so that there's no concern about daughter cells.