I think there were a number of things happening. First, the grain we have now, like many other post agricultural products, has been altered. Second, grains can be dried and stockpiled, as can legumes. Third, the stockpiled grains were fed to the lower class in differing forms.
Generic, all-purpose flour is bleached and treated so that it loses it's nutrients an has to be "enriched". Other flours used for bread are grown for their gluten content. Gluten is after all what gives bread it's texture. You can even buy special flour made for bread machines that is higher in gluten than other flours. Today when we think of grain, the first ones that come to mind are wheat, oats and corn, wheat was only a portion of the grain consumed. Other grains, like millet and sorghum, are easier to digest.
Others have stated that grains can be stockpiled. Legumes were also stockpiled. In this way, when times are thin for agricultural societies, there is still sustenance. Legums provided protien while the grains filled the tummy. Bread was also a portable food. Grains, bread and beans could also be carried into battle and on ships for long voyages.
Most of the grain was consumed by slaves and the lower classes. Although bread and some grain was consumed, the upper classes had greater access to high quality meat, especially in the middle ages. The lower class was sustained on gruel, vegetables and the tougher cuts that were thrown away by the upper class. Poor storage methods led to fermentation and the long, slow cooking further diminished the toxins.