All perfect praise be to Allah, the Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad, sallallahu ʻalayhi wa sallam, is His slave and Messenger.
First of all, we would like to point out that, according to the majority of scholars – contrary to Ibn Hazm – a woman's prayer at home is better and more rewardable than her prayer in the masjid, as it was authentically reported that the Prophet, sallallahu ʻalayhi wa sallam, said, “Do not prevent your women from going to the masjids, and their homes are better for them.” [Abu Dawood]
Eating raw garlic or onions is not prohibited according to the majority of the scholars; however, if you eat them, then going to the masjid while their smell can still be felt is disliked. Another view held that it is prohibited. Ibn Qudaamah said, “It is disliked to eat onions, garlic, leeks, radish, and everything that has an unpleasant smell because of its smell, whether the person wants to enter the masjid or not, as the Prophet, sallallahu ʻalayhi wa sallam, said, ‘The angels are offended by the same things that people are offended by.’” [Ibn Maajah]
If a person eats such foods, he should not go to the masjid. The Prophet, sallallahu ʻalayhi wa sallam, said, “Whoever eats from these two trees (i.e. plants) should not come near our place of prayer.” Another version of the hadeeth reads, “...should not come near us in our masjids.” [At-Tirmithi: good-authentic] ... It was narrated on the authority of (Imaam) Ahmad that a person bears a sin for doing that because the general indication of the hadeeth suggests prohibition. Moreover, harming Muslims is prohibited and doing this harms them.”
Accordingly, you have two options: either you refrain from eating garlic or onion when you wish to go to the masjid, or if you insist on eating them and their smell can still be felt, then do not go to the masjid and pray at home instead. But as for doing both; eating garlic or onion and going to the masjid while the unpleasant smell is still present, then this is unacceptable.
It is often not enough to brush your teeth with toothpaste or the like because the source of the smell is the stomach, and not the mouth.
Allah knows best.