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 is His slave and Messenger.
The basic principle with regard to trade is that it is permissible, and when coupled with a good intention, it becomes an act of worship, like all permissible acts. According to some scholars, trade is the best source of livelihood. As for the obligations and prohibitions pertinent to trade, it is difficult to list them all in a brief Fatwa, but the fundamental principles of the prohibitions of sale transactions, as Ibn Taymiyyah said, revolve around three things: 1) Riba (interest), 2) injustice (by means of cheating, deceit, and the like), 3) and Gharar (uncertainty about the consequences of the sale) and Jahaalah (lack of information about the sold item), and this category includes gambling.
The basic principle is that it is permissible to sell sweets (cakes) to all customers, except for those whom the seller knows that they will use them in what is forbidden, and in this case only, the sale is prohibited according to the opinion of the majority of scholars, because it involves cooperation and assistance in committing sin. Allah, The Exalted, Says (what means): {…but do not cooperate in sin and aggression.} [Quran 5:2]
With regard to birthday parties, contemporary scholars have different opinions regarding the ruling on holding such parties, and the opinion that we adopt here at Islamweb is that it is prohibited. Accordingly, it is not permissible to sell cakes to be served at birthday parties.
As for weddings and the like, the basic principle is that they are permissible, and therefore it is permissible to sell cakes for weddings and other permissible parties, unless the party is forbidden because it involves drinking alcohol or men and women dancing together. In this case, it is forbidden to sell cakes to be served at such a party.
Allah Knows best.