Indeed, considering Tolkien's otherwise fully-defined universe (and the industrialisation in Mordor indicating that it can be done), it's a fun question, and they rather use the question as as springboard into quite a ranging discussion of the factors behind real Industrial Revolution rather than a comic-book-guy-style tear-down of LoTR specifically.
EDIT: It took quite some time between the early days of the industrial revolution and the first semi-automatic guns. Ignoring LOTR for a minute, if in story taking place in the 17th century the question of "why didn't X use a colt .45" is easily answered, because it wasn't invented yet.
Probably the most honest reason to not have guns in Middle-Earth is that only stupid orcs, not the elves and dwarves who could easily develop them as school projects, would be interested in such tasteless weapons.
There were weapons, powerful weapons at that, but they depended heavily on artisanal production even if certain groups managed to reach manufacturing scale.
Also, Middle Earth is still licking wounds from the great wars with Melkor, which took away most of the advanced regions, and what Gondor and Arnor tried to rebuild got heavily whacked down by wars.
Random subsistence farmers spread across small hamlets do not make for industrial base, whereas Saruman and Sauron could use force to speedrun the development to provide resources for their forces (as both had knowledge of how to do it, even if we only take into account their experiences during wars of Beleriand - meanwhile the wizards other than Saruman stick to their oath of non-interference)
The remaining higher technology groups either lost the capability (Gondor), were destroyed (Arnor), are fighting constant war with Orcs with occasional dragon making problems that prevents building up proper industry (Dwarves), or are depopulated depressed groups that while not hoarding, do not interact with others anymore much and mostly use what remains of their industrial base to facilitate the last days of their race (Elves outside of Mirkwood - those in turn are trying but don't have much to build upon since Moria got overrun and they lost their main trading partner for technology).
The rest is down to subsistence farming levels without base of previous knowledge to rebuild or at least inspire.
So the very out-of-universe answer is: Because Tolkien decided against it. So the better question, and also the one we can use some source material to answer, would be why Tolkien decided against it and wrote a classic fantasy story.
There's no Industrial Revolution in Anglo-Saxon mythology. Including it would have jarred in a dyschronistic way.
More than that, fantasy is based on nostalgia for heroic simplicity and straightforwardness, with a dash of magic to instil some child-like wonder.
The Industrial Revolution operated on a completely different narrative and moral basis. It was more about colonisation at home, using mechanisation to organise forced labour.
It's hard to be a brave Romantic hero in that kind of setting.
Generally in the Middle-Earth, the parts we see, are post-apocalyptic environment constantly wrecked by wars and depopulated so hard most people are too busy raising crops to survive.
It has that, given that almost everyone is enslaved.
well, if there was pump guns, it wouldn't be a medieval setting anymore, as you need some industrial base to manufacture them, industrial base which isn't exactly compatible with a medieval setting. Not to say you can't have guns in fantasy (Pillars of Eternity and Warhammer fantasy come to mind), but they are usually more primitive.