What non-Frank Herbert explanation is there for training solders in the use of slashing or stabbing weapons in an age of hand held laser projectile weapons?
Technology fails sometimes --- be prepared for when you can't hide behind a random storage case and shoot at your enemy like a coward!
Your enemy won't always be content to hide behind random storage containers fifteen yards away from you, trying to plink you with their own lazer guns --- some may be creeping along the service conduits above your position, only to drop down behind you! Others may phase-shift right in front of you! Some's armour or even skin might eat your weak little lazer pellets for lunch as they come charging towards your position! You'll need something sharp and pointy for close in work.
Some technology is just too finicky to be playing at Okay Corral --- just like shooting a lead bullet inside an airplane is a dumb idea, so might shooting a lazer gun inside a shuttle craft or on the bridge of a Starmada destroyer. Lots of computer & display terminals, input devices and so forth that took the IT guys ages and ages to cobble together, and you want to punch all that work full of lazer pellets!
The sword is simply a more elegant weapon, a weapon of flowing motion and graceful warriors caught up in the Dance of Death, struggling to be the one remaining to bow at the end of the set.
Same reason we have bayonets and trench knives. Sometimes you run out of ammo, damage your primary weapon or drop it, and sometimes close quarters and speed require them.
Also stealth reasons, the classic laser beam points straight back to the shooter and may not be immediately lethal depending where you hit and doesn't cause massive bleeding, but chopping off your opponents head is definitely lethal. Slashes may not kill immediately but they don't cauterise the wound as they hit so massive hemorrhaging is just as lethal.
Intimidation, a sword or knife is a very intimidating weapon. If terror is part of your military strategy then a few examples of hacked to pieces bodies would be pretty terrifying.
1) It's dangerous to use the kinds of weapons you are talking about because science. For the same reasons you would not use a flame weapon at a gas station. It's not conducive to anyone's survival.
2) Shortages, both regulatory and/or apocalyptic in nature. There might be hand laser weapons, but getting your hands on the power-packs is very difficult. You can jury rig something, but it isn't going to last. Best save it for emergencies.
3) Security Alert!! The second a weapon that's high tech fires, BAM, the feds are there. Security tech locks on your position pretty much instantly, trapping you. with a bladed weapon at least there's a chance. This can be a planetwide automated system controlled by an AI, which nobody can do anything about, so they have to work around it. Or it can be something that's developed for the battlefield, a lock targeting system that makes laser weapons a bad, bad idea.
4) Treaties. Hear me out here. Mutually assured destruction...While there are laser weapons, an agreement is in place. Anyone uses them, they become the bad guys and alliances are formed against them.
5) War is actually thought of as a game, by those higher up. It's a gentleman's agreement to use blades.
6) Lazer guns destroy the value of something that needs captured. Might be tech, might be something else (like nature). Along the lines of delicate tech being around like in elemtilas' answer.
Because they are better in some situations?
Basically you start by giving the laser weapons some major drawback that makes them useless in some situations. And yes, this is the generic form of the Frank Herbert explanation. But it can't be really helped since the military will not waste time training soldiers to use something unless it superior to their other weapons in a some situations.
Fortunately we can narrow it down some by noting that people would still have access to the guns we currently have, so apart from some speculative superiority over hypothetical future weapons of unknown properties they also need to outperform weapons we know about and understand.
There are some obvious things mostly already mentioned by others. No need for ammunition, can be used silently and without a visible flash, harder to break thru abuse or lack of maintenance, training itself might be beneficial, vastly reduced chance of collateral damage and some defensive ability without damage to opponent.
Unfortunately non of these really justify a sword. Any melee weapon can do. In practice a knife is more convenient to carry and if it can be affixed to your laser rifle works as a spear which is superior to a sword in most cases where a knife is not. An axe is also possibility as it is a useful tool in wooded areas.
As also already noted by others it is practical to use hardware you are already carrying anyway as a melee weapon. A laser rifle can be robust enough to use as a club. A shovel (or a tripod) can be used as an improvised club or even mace. Training soldiers in such use would generally be more useful than adding another weapon for them to carry.
And if your army is aggressive about melee training to increase aggression or physical conditioning they can actually modify their hardware to be more usable.
If you train soldiers to use the rifle as a basis for a melee weapon, you will design the rifle to be robust enough to handle that. You will add the hand grips to make the rifle easy to swing as a mace. Attachment to affix a blade so you get a short spear is cheap and obvious. But a weapon might have striking surface for swung use as well. Bit of hardening would make a good mace. Affix a cutting blade and you have an axe. Albeit not a particularly good one.
Typically, Ithink the main point of going that far would be to condition to soldiers to keep fighting even when they cannot use their rifle.
Ace Levy: Sir, I don't understand. What good's a knife in a nuke fight? All you have to do is press a button, sir.
Career Sergeant Zim: Put your hand on that wall, trooper. PUT YOUR HAND ON THAT WALL!
Career Sergeant Zim: The enemy cannot press a button if you have disabled his hand. Medic!