This is a very common question, but I have yet to find a good theoretical answer to both questions (diesel has higher flash point BUT lower spontaneous ignition temp.)
Flash point and autoignition temperature measure different things: gasoline and diesel are optimised for different ignition conditions
First, the standard definitions.
Flash point Flash point is the lowest temperature at which a liquid can gives off vapor to form an ignitable mixture in air near the surface of the liquid.
Autoignition point The autoignition temperature or kindling point of a substance is the lowest temperature in which it spontaneously ignites in a normal atmosphere without an external source of ignition...
The first point to make on the differences between diesel and gasoline is that the liquids are designed for different properties in engines.
Petrol/gasoline engines need fuels that vaporise easily to give a mixture that is ignited by a spark. So they want a mixture that is easy to ignite but that does not explode spontaneously in the engine (which is bad for the engine and upsets the control of when the exploding fuel happens). So a low flash point is good but a low autoignition point is bad.
Diesel engines work differently. The explosion is not triggered by a spark but by compression of the fuel mixture which heats it and leads to a spontaneous explosion in the mixture driven by the heat of compression. So a diesel engine wants a specific autoignition temperature and one that is low enough to create reliable fuel ignition.
So the properties of gasoline and diesel are there by design as that is how the engines they feed are meant to work.
The chemical properties that create these properties are, broadly, different mixtures of hydrocarbons. Gasoline tends to be more volatile and contains far more unsaturation (aromatics and branched hydrocarbons). Volatility is necessary so the mixture can be vaporized easily to make a flammable mixture. Diesel tends to have many more straight chain hydrocarbons which are more susceptible to attack by oxygens in the air. Diesel also tends to be much less volatile than gasoline as volatility is much less important to creating an effective mixture in the engine. This has the side effect of increasing the flash point for diesel.
So design intent and chemical properties make the metrics different.