This ḥadith teaches that onion and garlic are not forbidden; a person may eat them. However, once he has eaten them he must not enter the mosque, pray in congregation, or attend a lesson of sacred knowledge, because the angels are offended by their repugnant odor. The scholars likewise state that anyone whose teeth or mouth emit an unpleasant smell, or who carries any offensive odor, must keep away from the mosque until he removes it, for the underlying reason—harm to the angels—remains the same.
If someone asks, “Suppose a person uses something that eliminates the smell; may he then enter?” the answer is: Yes, provided the remedy removes the odor completely and no smell issues from his stomach. In that case there is no objection, for a ruling depends on its effective cause, existing when the cause exists and lapsing when it is absent.
If another asks, “May a person deliberately eat onion or garlic so that he will be excused from attending the mosque?” we reply: No—this is forbidden. One may not contrive to drop an obligatory act by any pretext whatsoever. Yet if he eats them simply because he likes them, then the eating itself is permissible, but he must not approach the mosque until their odor has dissipated. And Allah is the One who grants success.