Detergents prevent contaminants from plating out; keep them in suspension. Dispersants prevent them from agglomerating, which would allow them to overwhelm the detergents and fall out of suspension. These two things work together to prevent deposits. If we are talking about an emulsification like sludge, which hasn't adhered to a surface (unlike varnish) then the action of agitation of the oil flowing over it is enough to break some of that up, which then gets put in suspension in the oil.
If something with high polarity and/or solvency is also in the oil, like some esters or AN's, then the oil can actually work to slowly remove existing deposits from surfaces.