Hay shed fires can be caused by sparks from machinery, grass fires, and so on, but the other way that hay sheds catch alight is from spontaneous combustion, where moist hay generates enough heat to burn.
This Primefact lists the risk factors for hay shed fires from spontaneous combustion, how and when to monitor bales, how to measure moisture content in forages, how to use additives to reduce mould and heating, some risks for silage, and the effect of heating on feed quality.
The 'safety first' section notes that you must be very careful if you suspect heating in a hay stack. Walking on the stack could cause it to collapse, especially if the centre is hot and has a burnt-out cavity, so follow the precautions described in the Primefact for safer access. Also note that you should be very careful if you are moving heating bales from the stack, as any disturbance could expose hot spots to oxygen and the stack could ignite.
There is also a section in the Primefact on the increase in hay shed fires during drought. While you would expect that hay made in drought times would have adequately low moisture content, some fires have been caused by apparently dry cereal hay where stem joints and seed heads still contained enough moisture to develop a heating reaction; and the raised water-soluble carbohydrate levels in the hay from the effects of drought meant microbial activity and therefore fire risk was higher. Take extra care with drought-affected crops to ensure hay is dry before baling, and monitor sheds and stack for signs of heating.