It’s the same reason modern militaries still issue combat knives. Because, if your primary weapon fails, and you really need to kill someone, it’s a good idea to have a contingency.
If I’m remembering correctly, The Empire still issued vibroblades to some specialized Stormtroopers as a backup. The assumption is to see if they’re actually wounded, but still alive. There’s a scene at the beginning of A New Hope, where the Stormtroopers are checking their fallen buddies, poking them. Now, their armor does (apparently) save their lives sometimes. We see enough getting gunned down in the original trilogy to make that point. You don’t want to arm Rebellion Era Stormtroopers with vibroswords because their armor won’t fully protect against blasters. And Star Wars is one of those settings, but you really need to evaluate who can and can’t get away with using melee weapons. I mean, this is worth talking about, because you can legitimately have characters who approach combat from a melee perspective in a setting with advanced ranged weapons.
The only reason the Jedi can get away with using a lightsaber is because of their superpowers. There’s a lot of primitive worlds where you don’t have advanced ranged weapons, and when you’re dealing with them, plasteel armor and a blaster will still offer an insurmountable advantage. Even just looking at the Tales of the Jedi era stuff. Yeah, Star Wars isn’t actually a good counter example there.