I guess you are talking about the restriction modification system, not restriction enzymes in general (which are used a lot in the lab, for example). If so, this paper might help answer your question.
I have not read through it totally, but at least some viruses trigger the downregulation of restriction enzymes to make them cleaving their DNA less likely. Restriction enyzmes are also quite selective for the site they cut at, so single nucleotide changes at this site, might, if the phage is lucky, not change the function of the encoded gene, but keep the restriction enzyme from binding (and thus cleaving) at that site. Mutating helps a lot. And it is fast in those little critters.