The real time to buy a lottery ticket is when the expected payout - the payout times the odds that at least one person will draw the winning number - is more than the expected gross revenue since the last drawing.
Here's a simple example:
pick 4 numbers from 1 to 100. The odds of winning are 1 in 100,000,000.
If 100,000,000,000 million people play every week, then in the first week the odds that SOMEONE will win are close to but not quite 100%, so the expected pay-out is a bit less than $100,000,000. Smart money says don't play.
To keep things simple let's assume that the next week only 100,000,000 new people play. The odds that SOMEONE will win are close to but not quite 100%. They are certainly over 50%. The expected payout will be a bit less than $200,000,000 and certainly more than the $100,000,000 that bettors put on the table this time around. The smart money says play.
If you don't see how this works, assume YOU are the only bettor in week two and you buy all 100,000,000 tickets using a random-number-generator. There will be duplicate bets (if you weren't the only ticket-buyer, these numbers would result in you having to share the prize), but you will cover well over 50,000,000 of the possible combinations. If you win, you more than double your investment, and the odds of you winning are more than 50/50.
Of course in the real world it's almost never going to become a good investment to buy a lottery ticket if all you care about is financial return. Why? Because as the jackpot goes up, people who normally don't buy tickets do so. Why? Some do it for emotional/fantasizing reasons. Some do it so they can tell their grandchildren how they "almost won the big one." Some may do it because they think the number of new tickets sold will be low enough to make it a "smart decision" to buy a ticket.
Bottom line: There may be good reasons to buy a lottery ticket, but "because it's a good investment/because it's a smart gamble" is almost never one of them.