Pad Spacing violates trace spacing
You need a large footprint part. If you need 5 mm clearance, you can't just use an 0805 capacitor or resistor and expect to have your clearances satisfied; you would want to use a properly rated high-voltage part, which should have appropriate clearance and creepage due to its design. That may mean wide lead spacing on a through-hole diode, or the use of an extra-wide SOIC package for an isolation IC, or even a bespoke package designed specifically to accommodate clearance and creepage requirements, but you definitely shouldn't just use an ordinary part.