A coating can flow into surface irregularities and gain some physical interlocking as it forms. This is mechanical adhesion. Molecular interactions at the interface also contribute to adhesion; the details depend on the materials.
These are useful mechanisms, not two switches operated only by sandpaper and primer. A rough surface can still be contaminated or weak. A smooth surface can accept a compatible system.