Phasers are excellent weapons. Their damage is adjustable from stun to "melt/blast solid rock", which even happens in TOS.
They have no recoil and can fire continuously, briefly, allowing one to adjust aim or simply focus down a particularly hard target. Warning, surprisingly graphic:
https://www.youtube.com/watch?v=8Q5EXhJzdecThey're compact and light, even the rifles.
They can be reloaded with power packs, but it only comes up in extended missions. They clearly have a very high capacity.
They're even repurpose-able as smart mines or grenades, with fairly dramatic yield.
Named characters and villains have super dodging powers, but that doesn't mean the weapons are bad. And when a phaser does hit, it usually does what it's meant to. Some aliens have strange biologies, but even battle-ready Klingons get cut down in the DS9 war. Cases where people shrug off "lethal" phaser blasts are due to mid-level settings, or pure narrative fiat. Again, "explode rock walls" mode is a thing.
As for guns, and I don't know if this actually gets addressed, but Federation ships have very effective force field technology through their halls. They dynamically patch the hull with them. Intruders armed with energy weapons can blast through (reference: boarders are ever a threat whatsoever), but what good is a handheld gun against something that accurately repels hi-v particles while containing atmosphere? Sounds like a great way to shoot yourself.