The question is not "what's best for you", but "how to keep as many people as possible well fed and reasonably healthy". And an important part of it is that everyone gets enough calories, even the poor, and even during hard times.
Grain is an efficient source of calories, and grain products tend to have a good shelf life and don't need refrigeration. And ideal baseline for keeping people from starving.
But grain is good for calories, but not enough to keep people healthy, you also need vitamins, fiber, etc... So you introduce the second food group: fruits and vegetables. A bit more expensive and more involved than grain, but it provides most of the things grain don't.
Now, we are at a vegan diet, and experience has shown that it can be perfectly healthy, but in order for it to be, you need to do a significant amount of bookkeeping, and you may need some slightly exotic food to avoid deficiencies. So, not enough for the general population, so you introduce animal products. Even more expensive, but now you have everything you need, with good margins.
The top of the pyramid is for the products for which the needs are covered more efficiently by the lower layers.