All perfect praise be to Allaah, the Lord of the worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
This transaction is absolutely forbidden, because it is sheer gambling, and it is forbidden by the Quran, the Sunnah (Prophetic tradition) and the consensus of scholars to deal in gambling. Such a prohibition would not be made lawful by using the money collected from lottery for good purposes, such as building mosques or Islamic schools, because the means takes the same ruling as the end. If the end is approved by Sharee‘ah (Islamic law), then the means must also be approved by Sharee‘ah.
It should be noted that only lawful resources should be utilized in building mosques, because mosques are the Houses of Allaah, and the Prophet, sallallaahu ‘alayhi wa sallam, said:
“O people, Allaah is Good and accepts nothing but good.” Also, Allaah commanded the believers to observe what He commanded the Messengers with Saying (what means): {[Allaah Says] {"O messengers, eat from the good foods and work righteousness. Indeed, I, of what you do, am Knowing.} [Quran 23:51] He also Says (what means): {O you who have believed, eat from the good things which We have provided for you} [Quran 2:172] Then he mentioned a man who travels a great distance and becomes disheveled and covered with dust, who raises his hands to the heavens (and says), ‘O Lord, O Lord,’ when his food is ill-gotten, his drink is ill-gotten, his clothes are ill-gotten and he has been nourished with unlawful food, so how can he receive a response? [Muslim]
This is regarding those who want to participate in the lottery. However, those who are involved in it and want to repent to Allaah The Almighty should dispose of the money they have earned in charitable channels.
Allaah Knows best.