Hay gets moldy when it gets damp. That can happen easily if not stored properly. If the bags are stacked against a cold outside wall, moisture will condensate where the bag touches the wall. Hay is a good insulator, so an outside wall will get cold where hay is stacked against it - but the front of the bags are warm from inside -> all hay contains some amount of water, and it will migrate to the cold spots in a bag or container.
Same goes for pellets, never lean a bag of pellets (I buy 50lbs bags, guess how I realised that...) against a wall that is cooler than the ambient temperature.
Bales or lose hay can have that problem too if stacked on a cold floor or against an airtight outside wall. Or if they were made before the hay was dry enough. Any horse grade hay is pretty much ok, here, single spieces hays like Timothy or Orchard are not really available, it's just what grows wild on the meadows, I make most of the hay I need myself.
If hay smells bad, moldy, discoloured in some areas, or even feels damp (you wouldn't notice that in a bag that was stored wrong some time in the past since the moisture will distribute again when the temperture gradient is even throughout the bag) I wouldn't feed it.
When it is moist enough, even if it's just patches, it will spoil within days, when hay gets wet you can consider it gone, if not in a stove or spread out in the sun right away it wouldn't dry fast enough.