tl;dr
What i have in mind, soon as ancient people learn that they can trade things with their own value like barter, discovered gold and silver or other precious stones/stuffs, people start betting and learn gambling on their own way.
It's difficult to know things like this especially for a question of "when" for a timeline since its now a history, although the "where" like the origin of some form of gambling might be a little easier.
It's quite fantastic right? As soon as they know that things can be traded, There are this people will come up in the new ideas. But i think in the early era of gambling for sure there are a lot of loop holes that smart people uses or like trick the players. But now gambling is really pure luck well that is because of the technology we have right now.
Imagine using a time travel machine and going back to the past (which can't be happen cause you can't time travel in past) And bring a device that can trick all this gamblers, you can build your own empire.