This is one of those pet peeves that really annoying. I don't mind if you've a society that clearly has advanced to the gunpowder stage and then somehow figured out how to make melee weapons better than guns, whether it's a lightsaber or Ninja's sword in Metal Gear, or maybe because punching each other to death is just cooler. But there are a lot of games that clearly take place in your medieval level of technology who somehow has access to guns and mechs, and it really makes no sense whatsoever since the mechs won't even be stronger than say a generic Ogre. It's almost like whoever designed it figure they got to hedge their game for the FPS crowd to include guns no matter how little sense it actually makes.
I think a lot of it has to do with Japanese culture that has permeated the fantasy genre over the last 50 years.
Japan, before the Shogunate, was the largest producer of firearms in the world. After the unification war, firearms were banned, and the society was effectively iron aged; but guns would occasionally leak in. Japan also LOVES the fantasy that a technologically advanced society existed earlier than the memory of the current society - you can see this in most Final Fantasy games, Xenogears, and Final Fantasy Tactics.