So why do people do it? I suppose a lack of math skills has something to do with it, but I'm pretty sure the real reason is that people like to dream of a fairy-tale-style life change. Quit your job, buy your dream home, pay off all the bills, travel the world...that's the stuff of dreams. An opportunity to realize them is attractive, even if you know the chances are so low that it's almost as likely you'll pick up a winning ticket off the street as pick the numbers yourself.
All that is fine if you know it going in and have the money to spare. Unfortunately, a lot of lottery sales go to people who can least afford to throw money away. The same "big dreams" effect that makes the lottery attractive is most likely to appeal to those with the least spare cash.
But wait, isn't the lottery money usually used to pay for schools and similar government programs? That sounds great, until you realize that the use of lottery funds is used as an excuse to avoid funding through taxes (mostly property and income taxes). If the lottery ever stops making money, those programs will be in some big trouble. Even if that never happens, this kind of school funding is effectively a tax transfer from the wealthy (who would pay a lot of income and property taxes) to the poor (who buy the majority of lottery tickets).
Rather than go on further in this vein, I'll just put a link here to John Oliver's piece on the lottery on Last Week Tonight. Highly recommended, if you haven't seen it yet. He talks about all the things I've mentioned and a few more besides.
So, what should be done? I'd love to see state-run lotteries eliminated completely, but I know that's incredibly unlikely, since it would require action by the very people profiting from the system. I think the best case scenario is restrictions on how lottery money is considered in funding formulas, such that other sources of funding (i.e. income and property taxes) have to be used to pay the full budget for schools and other public services used by all income levels. The lottery money should be directed to programs used primarily by lower-income people (social services, rent assistance, Medicaid, etc), since they're the ones putting the money in. It's not a great scenario, but it's better than the current one.