I think you shouldn't just focus on the monetary outcome.
If you play a game for 4$ (winning 1Mio.$ with a probability of 1/500'000) whiches fair value would be 2$. So playing this game is rational if the thrill and the dream of beeing rich (as the non-monetary benefit of the game) is valued more than 2$ (a coup of coffee), which is very likely.
I can think of two biases that might cause an irrational decision for lotteries:
People tend to overweight small probabilities, so they calculate with a too large expected value.
Another problem might be, that people are not able to estimate the utility of a large amount (e.g. 2mio$). They think to be able to live the rest of their life in luxury without working. (But after paying taxes and your first sports car, there's not much left). So they calculate with a wrong (too high) expected utility.