If virtual particles sometimes add more mass/energy to a system then was inputed or comes out in the output, how do they not violate conservation of mass/energy.
Virtual particles are not real. Though sounding like a tautology, it is an important one - they are not actual states in the asymptotic Hilbert spaces of a quantum field theory, where particles usually live. They are a name given to internal lines of Feynman diagrams, which, in turn, are mere computational tools in a perturbative approach to QFT. Nothing in the formalism itself justifies imbuing these lines or diagrams with any more meaning, so it is unclear what it means to say "virtual particles sometimes add more mass/energy to a system" as you do in the question.
Conservation of energy holds, quantumly, only inside correlation functions and up to contact terms - the quantum version of Noether's theorem, which classically guarantees conservation of energy, are the Ward-Takahashi identities. Even if the internal lines of Feynman diagrams represent particles in any sense, conservation of energy/momentum is only guaranteed to hold as a statement about expectation values, so that individual states may well, from a classical viewpoint "violate conservation of energy". (Note, though, that "energy of a state" may even be an ill-defined thing to say)