Actually, gunpowder is one of those twitchy things that seems easy in hindsight, but very difficult to come up with practical uses for at the time.
Essentially, any culture which as significant access to sulfur, charcoal and nitrates can stumble across gunpowder. But there are some caveats there. Charcoal is universally available. But Sulfur is not, so you need a culture either located close by, or which has pre-existing trade networks available for moving quantities of sulfur. And you need a culture which has some understanding or appreciation of nitrates as a substance, or the refinement thereof.
So basically, you need the raw materials, and a culture which has access to and appreciation of these raw materials.
The next part of the equation is that you need a culture with an impetus to mixing raw materials in sustained ways.
The Chinese, as is famously understood, were not searching for gunpowder, they stumbled on it, trying to come up with an elixir for immortality. But look a little deeper. Chinese medicine had catalogued literally hundreds of substances from gravel to peat moss, mercury to lead, inanimate and organic, and ascribed medical qualities to each substance. They even ascribed medical curative properties to fossils. So that became a foundation for a quest to cure illness or enhance health by combining different substances.
The original recipes for gunpowder by the way included honey and mercury. And this raises another issue. For successful gunpowder, you need an optimimum ratio. It escapes me at the moment, but I can look it up if anyone needs it. Less optimimum, you may just get a lot of smoke and sizzle. From the discovery of gunpowder, it took the Chinese a few centuries to work their way to the optimum formula.
Finally, while it may seem intuitively obvious to us to weaponize it, that's not so clear for people who have never seen the stuff. It's hard to deal with, hard to get the ratio's right, and it tends to separate out into its constituents. It may produce a flash and a lot of smoke, but that doesn't necessarily win your battle.
The Chinese found their best and earliest use for gunpowder in fireworks, so we can assume some social evolution - you get a lot of 'bang' for ceremonies and showmanship.
Weaponizing it, for the Chinese, was a lot tougher. They experimented with things like fire lances. Didn't save them from the Mongols. It would be a few centuries before both gunpowder and gunpowder tactics were advanced enough to make a difference.
Basically, there's a lot of flukes involved, and perhaps a lot of blind alleys. It could be discovered at any time by anyone, assuming a reasonable degree of sophistication and access to resources. I'd say any reasonably competent bronze age society, or even a sophisticated Neolithic society might manage it. But its hardly a straight line to practical use.