why can't Barbarians or Orcs have alchemy skill? If your anal about rules then a half Orc alchemist who lives with the orc tribe. Orcs could capture an Alchemist and use him. One Treant would get a chance to bat away the kegs. Two Unless the players have high skill in siege engines how are the acurateally throwing the barrells? and What are the Elve's and other Treeant's going to do when you start blowing up Treants? Forests usually have lots of Treants. they are slow to act but a month later they may come out of the forest when the PC's arent there and rip thier city completely apart.
If your fiends aren't smartly using every single thing they can against the players you arent' playing them right. Or even without alchemy all the enemy needs to know is fire burns gunpowder. Shaman summons fire elemental during battle . Boom. also mideivel black powder is not like the modern stuff. It should just fail to burn periodically. If it get wet you can't dry it out and then use it. A lot of undead are intelligent and formerly living . In a world with gun powder some magical beasts will know what it is. And seriously how do you throw a keg of gunpowder without it breaking and scattering the Gunpowder all over the ground just the act of picking it up and hurling it might crack it enough that the powder would start to come out and then no big boom? two an exploding keg of gunpowder wouldn't have a big blast radius and flying pieces of wood would suck but not be grape shot or cannonballs.
And as far as alchmist and production that's when enemies send assasains or teleporting mages to capture them and start thier own production. Or even more simply Some smart guy watches party makes his own factory if its that easy maybe a dozen factories and starts selling gunpowder in bulk to everyone one and the players now have to deal with Orc's, Goblins and other PC's that can buy or steal gunpowder and use it against them. That's how technology advances one guy gets a temporary advantage and then someone else runs with it.
My favorite idea off the cuff though would be to send in water elementals, or if the game is high enough level some elven druid may just say enough and call a hurricane in on thier factory, and city.
You are once again missing the forest for the trees.
A barbaric savage orc tribe won't have alchemists because they are barbaric savages without education, the same way they won't have a chemist or physicist or likely a wizard. I used BARBARIC and SAVAGE for a reason. Alchemy is a civilized thing.
Now, if MY ORCS ARE DIFFERENT, that's fine, but I'm using a trope, and you're trying to change the trope. Savage, uneducated tribes of humanoids won't have alchemy and gunpowder, any more then viking raiders did. Low tech, low education, no production.
PC's can figure out all kinds of ways to throw the kegs.
Treat hits the burning keg, it explodes and blows up. Not a solution.
Substitute fireball for kegs in your killing treants and elves, and you can see you missed the point again. Dead foes don't know how to guard against stuff. You are instantly turning it into DM Fiat arbitrary consequences. Those 'examples' are meta-game events which would occur if you were killing treants and elves, they have nothing to do with using gunpowder to do so, so you're making false examples.
Fiends don't have alchemy skills, and most of them are brutes, not clever masterminds. They don't have the mindset to use such crutches. -- There, see, I shot down your false example as easily as you set it up. I've never seen a fiend using gunpowder or guns, even though both are available in Pathfinder, and presumably in the Abyss. Not reliable against other fiends is my guess... plus Fiends don't normally have Alchemy to make the stuff.
Arbitrary 'this don't work' is arbitrary. You're talking a trained and experienced alchemist, not a medieval chemist. The stuff works, and works reliably. You might as well implement rules for 10% spell miscasts because medieval, and Weapon Breaks on 1 because Medieval, then.
SOME undead are intelligent. MOST undead never used guns or gunpowder, and don't have the alchemy to make it. Go look at the stat blocks. Not every undead is a lich or vampire, and unless they died as gunmen, they aren't proficient in using gunpowder weapons, either. You are once again ALTERING THE GAME to stop gunpowder use. It's also a trope that undead don't really learn new stuff. They are dead, after all. Even the vampires cling to the pageantry of their time, and don't adjust to new eras.
DM Fiat: Now kegs don't work like the game says. Oooookay.
90%+ of the enemies PC's fight don't have the wherewithal to send assassins or teleporting mages, and the latter is a VERY high level ploy. Again, the argument has nothing to do with gunpowder, it just has to do with violent PC's and consequences. Substitute 'fireball' for gunpowder, or 'chopping greatsword' in the hands of a skilled fighter, and your 'argument' is the exact same thing - a DM Fiat metagamey thing.
If the high level elven druid wants to send in water elementals or drown a city, gunpowder has crap to do with that, too.
If the orcs and goblins want to get alchemy in the future, that doesn't help them NOW, when the PC's are killing them. "After the end of the campaign, the goblins and orcs realize they can't be barbarians anymore, and start settling in and developing an education system and technology, stealing what they can, and in a generation or three, start making stuff of their own" doesn't help right now.
Metagamey DM Fiat is Metagamey DM Fiat that has nothing to do with actually using gunpowder now.