Celebrating the Mawlid (Prophet’s birthday) is bid’ah (an innovation). It is not narrated from the Prophet (peace and blessings of Allaah be upon him) or any of his companions or the Taabi’een or the Imams. Rather it was innovated by the ‘Ubaydis (Fatimids), who also introduced other innovations and misguidance.
The basic principle is that it is permissible to eat and drink sweets that are free of harmful ingredients, so long as that is not helping in evil or propagating or encouraging its survival.
It seems that buying Mawlid sweets at the time of that celebration comes under the heading of helping and propagating it; rather it is a kind of establishing that festival or eid, because an eid is something that people observe regularly. If it is their custom to eat this specific food or they make it for that festival, unlike their habits at other times of the year, then buying and selling it, and eating it or giving it as a gift, on that day, is part of celebrating that festival or establishing it. So it is better for you not to do that on the day of the celebration.
In Fataawa al-Lajnah al-Daa’imah there is a discussion to do with Valentine’s Day and buying sweets that have been coloured red and on which hearts are drawn, as an expression of celebrating that innovated festival. It says:
The clear evidence from the Qur’aan and Sunnah – on which there is consensus among the early generations of the ummah – that there are only two Eids or festivals in Islam: Eid al-Fitr and Eid al-Adha. Any festivals other than these, whether they are connected to a person, a group, an incident or anything lese, are innovated festivals and it is not permissible for the Muslims to celebrate them or approve of them, express joy on them or help with them in any way, because that is transgressing the sacred limits of Allaah, and whoever transgresses the sacred limits of Allaah has wronged himself. … It is also haraam for a Muslim to help with this festival or any other haraam festivals in any way, whether it has to do with food, drink, selling, buying, manufacturing, giving, corresponding, announcing or anything else, because all of that is cooperating in sin and transgression and disobedience to Allaah and to the Messenger of Allaah, (peace and blessings of Allaah be upon him), and Allaah says (interpretation of the meaning):
“Help you one another in Al‑Birr and At‑Taqwa (virtue, righteousness and piety); but do not help one another in sin and transgression. And fear Allaah. Verily, Allaah is Severe in punishment”
And Allaah knows best.