Since all of these foods are typically stored in dried form, there can’t be any microbial spoilage. The main factor is going to be fat content. All fats are subject to oxidation (which is a chemical reaction, not something living in the food). Oxidation creates some pretty nasty tasting compounds, which we call “rancid” flavors. They won’t make you sick, but the food is “spoiled” in the sense that no one will want to eat it.
All nuts are pretty high in fat, and most cereals (especially whole grain) contain some fat as well. Pulses are mostly very low in fat. But not all fats are equally subject to oxidation; it depends on their particular fatty acid composition. And some nuts contain other compounds that inhibit oxidation. Walnuts, for instance, are very high in fat, and but they’re also high in tannic acid, which is an anti-oxidant, so they end up keeping fairly well despite their fat content. Macadamias, on the other hand, will go rancid in a heartbeat because they don’t have a similar anti-oxidant.
There can be insect damage, of course; even though packages remain intact, you never know which products already contained eggs or larvae before being packaged. Grains are more susceptible to this than are pulses or nuts.