In Ayurvedic medical science, onions and garlic plus chives, shallots, leeks (all from the
Allium family) are
rajasic and
tamasic foods – that is foods in the modes of passion

and ignorance

(respectively). These two modes are avoided by yogis and renounced souls as unsuitable for offering to the Deity. Spiritual seekers eat only
sattvic foods – foods in the mode of goodness.
Some Allium foods, like garlic, are beneficial for health, but all alliums are nevertheless avoided by spiritual seekers because they stimulate the central nervous system, can act as a natural aphrodisiac, and disturb meditation. Strict Buddhists also do not eat Alliums for the same reasons.
In the Tao of ancient Buddhism each of the Allium vegetables is said to have a detrimental effect on one of the five organs - liver, spleen, lungs, kidneys, and heart and to contain enzymes which cause "reactions of repulsive breath, extra-foul odour from perspiration and bowel movements, and lead to lewd indulgences, enhance agitations, anxieties and aggressiveness…"
Mahayana Buddha forbade his disciples to take the five pungent roots (garlic, three kinds of onions, leeks) because they cause irritability when raw and, again, act as an aphrodisiac when cooked. And the breath from eating them drives away the good spirits who come to protect the yogi or devotee when reading sacred texts.
Of course there is no right or wrong; it's about what I know is good for me and for where I am on my journey. We need to consult an Ayurvedic or natural health practitioner before making any radical changes to our eating practices, because our lifestyle dictates our nutritional requirements.