Q) Is buying lottery tickets included in the prohibition of gambling?
A) One is allowed to buy lottery tickets, and the halachic issues that apply to gambling do not apply regarding buying lottery tickets:
Gambling usually poses a halachic issue of asmachta (which is a form of gezel). This means that a person putting down money on a bet obviously does not want to part with it, and were he to know that he will lose the bet he would obviously not put his money down in the first place. Therefore, the person who wins the bet is taking money that contains an element of theft; i.e. were the other person to have known originally that he would lose the bet he would never have gambled in the first place.
[For this reason, one who gambles may be disqualified from edus; which will mean that he cannot testify in a Jewish court of law and cannot serve as an ed at a wedding or divorce ceremony (see Shulchan Aruch Choshen Mishpot Siman 34 where these halachos are discussed).]
With lottery tickets, since the chances of winning are so minimal, the person buying the ticket knows that it is almost definite that he will lose the lottery and consequently he wholeheartedly parts with his money when he buys the ticket. (Additionally, purchasing a lottery ticket constitutes a kinyan which in itself overrides asmachta.[1]) Therefore, there is no issue of asmachta or gezel and the person who wins the lottery need not be concerned that the money he receives is tainted with gezel.
The other halachic issue of gambling is that a person who gambles as his occupation is classified as an individual who is not involved in yishuvo shel olom (i.e. not a productive member of society). Buying lottery tickets (even several on a regular basis) is a casual pastime and does not pose a problem of failing to be involved in yishuvo shel olom.
[1] שו”ע סי’ ר”ז סע’ י”ד כל האומר קנה מעכשיו אין כאן אסמכתא כלל. וע’ סמ”ע ס”ק ל”ח ששאר קניינים [היינו חוץ מקנין סודר] נמי מועיל. ולכ’ בקניית כרטיס הגרלת לוטו יש לכה”פ קנין סיטומתא (ע’ חו”מ סי’ ר”א)