preignition/autoignition is a problem with gas engines as the piston is squeezing the fuel/air on the compression stroke car.
In a diesel, the fuel is not added to the cylinder until you want it to burn, around top dead center, and it is squirted directly into the combustion chamber with the valves closed and the heat/air concentrated so it will ignite. This arrangement allows much higher compression ratios than spark ignition engines that add fuel to the airstream and compress it with the pistons before igniting it.