In my world superheroes are a branch of UNE (United Nations of Earth); think the EU for most of Earth. Many of them have super powers, but many do not. They have access to more advanced technology than the rest of the world, but they don't use guns in favour things like batons, swords, and knives. As they are part of the legal system, it makes sense to me to have this restrictions be a legal one. Is there a reasonable legal precedent that could make this feel more realistic.
Real World Precedent for Unarmed Law Enforcement
In the United Kingdom most cops are not allowed to carry guns. Since common citizens are not legally allowed to carry most firearms in most situations, they are not considered a necessity for law enforcement to carry either. Guns are only carried by specialized tactical teams who are maintained for dealing with illegal gun threats.
In your UNE, you could take this a step further by making firearms completely illegal for cops and citizens alike. Throughout history, anti-weapon laws have resulted in people going one of two ways: Either they are already criminals so have no qualms about bearing arms illegally, or they find the most lethal thing they can carry that is not illegal and learn to fight with that. So, your future tech criminals will have no problems 3-d printing their own firearms, whereas their law abiding counterparts will have no experience with or legal avenue with which to pursue the use of firearms; so, like the shaolin monks who learned to fight without swords, your superheros will be lawful expert combatants who've simply spent a lot of time learning to fight without a gun.
As this relates to the trend you see in the UK, your UNE has made all firearms illegal across the board; so, your culture can no longer justify law enforcement carrying firearms despite the occasional career criminal outlyer. Since, the government still needs to have specialists who can suppress people who break this law, the government uses "Superheros". Bad guys may still sometimes have guns, but as long as you have special tactical units with personal shield generators, or full coverage class IV body armor, or invisibility suits you can still have law enforcement who can subdue those offenders without having to shoot them which tends to be the primary goal of law enforcement anyway.
Fantasy World Precedent for Heros not Using Firearms
I most fantasy settings, there are TONS of examples of heros who use non-firearm weapons in a world where guns exist. Generally this is justified in one of 3 ways:
Option A: Guns are ineffective
Since you have a world with people who have actual superpowers, many of them may be generally unaffected by firearms; so, your mundane heros will need to utilize technologies and tactics other than shooting to hold their own. If your opponent has super regeneration like Deadpool, then guns will pass right through him, but a sword can cut him in half allowing you to more effectively disable him. If you have a super with metallic skin like Colossus, then bullets may bounce off of him whereas a high voltage hand taser might do the trick. Certain technologies like Holtzman Shields or sheer-activated polymers also have the potential to render guns ineffective compared to melee weapons.
Option B: Guns are obsolete
Since you have a future tech setting, there may be a plethora of NEW personal weapons that simply outperform traditional firearms for the purposes your hero has in mind. Power armor like that used by Ironman or 40k Space Marines allows one to simply walk up to a gunman and pull the gun out of his hand without putting himself at any risk of being harmed. Then you have things like electo-lasers, nanobot swarms, or Green Lantern's ring which could replace guns simply by being so much more versatile even without totally nullifying their effectiveness. Lastly there is the option of an offensive weapon that is just objectively more destructive than a gun like Thor's Hammer.
Option C: Guns are unconscionable
Most people who bare the title "superhero" have a general aversion to killing. Many heros like Batman, Daredevil, and Captain America would benefit greatly from carrying a gun, but choose not to for ethical reasons. And those that chose to use guns such as Punisher often wind up being seen as villains by these other superheros. While it is natural that some mundane superheros may WANT to use guns in your universe, they may choose not to because other in-universe superheroes are intolerant of killing. Since your superheros are bound by some code of law, it means that there are discrete rules to membership which could easily include a strict no-gun policy based on the moral code of your organization's founding members.
This kind of "no killing" rule often meets some level of resistance, but is ultimately enforced by the leading members in many heroic groups such as the Legends of Tomorrow, X-men, etc. and with these rules, guns tend to become useless... with the very rare exception of perhaps John Diggle who uses guns just to wound while following Team Arrow's slightly less strict no-kill rule.
Superheroes mostly fight other superpowered individuals -- fights against normally powered people cause nasty PR, especially if death results. Non-powered superheroes are included; the general opinion is that if you're willing to put yourself up as a superhero, you're powerful enough that you shouldn't be beating up normals. (This is perhaps regulations rather than law as such.)
For some reason, common superpowers result in bullets being ineffectual against the person. Given that all the weapons you list are hand weapons, perhaps it's a close personal forcefield that stops things that are not being actively propelled. Hence, a bullet, which is just flying from the explosion, stops, but a knife, being pushed by the hand, can penetrate. Once you train with hand weapons to the level necessary do this, you can't just switch to distance weapons without issues.
Physicists are quite certain that this shouldn't work, but that's why they call them superpowers.
There's a saying in Tunnel in the Sky by Robert A. Heinlein that I'm fond of saying and I think works well here: "guns make you stupid".
The logic behind this is that if you have a gun, you think you have power in the situation, which will cause you to become incautious. Heinlein mostly brings this up in the context of young adults going on an interstellar survival trip. The main character is specifically not given a gun because people with guns tend to think they're invincible, they don't bother trying to travel stealthily or pay attention to their environment because they feel like they can shoot anything that gives them trouble, and usually end up running headlong into the local megafauna rather than acting cautiously and stealthily and slipping around them. Being armed only with more basic weapons like a knife forces the protagonists to pay attention to their environment more, which helps in a lot of ways beyond just avoiding getting in fights with an angry stobor (like making you aware of danger before it happens).
Now apply this to superheroes. You might have a non-powered superhero with a big weapon, maybe some kind of kryptonite gun that can take down even supers, but the problem is it causes you to become dependent on the weapon. You become a one-trick pony, the only thing you excel at is shooting the problem, and if you can't apply your go-to solution you're at a severe disadvantage. Even then, you're only human, so what happens if you're fighting someone who has better reflexes than you and can attack before you pull the trigger? If you don't have weapons it forces you to fight defensively, forces you to hone your observational skills and fight asymmetrically in order to avoid picking fights with foes that can dominate you physically. Ironically, by not getting in direct confrontations and adhering to the time old Harry Dresden wizard confrontation style of "blowing up your enemy from across the street, or across town if you can", you're greatly increasing your survival chances against a superhuman opponent.
To quote Iron Man, "you have a big gun, you're not the big gun".
They are a POLICE force, and they are probably hunting other supers. That gun is going to be useful against the lowest of minions but above that you might as well bring your powered melee weapons and jetpack, or whatever your chosen tools of trade are. It gives you a better chance of actually beating these minions, it gives you a chance to ARREST them instead of murdering them with bullets and it cuts down on acceptable cas... collatoral damage. No bulletholes in cars, windows, furniture, walls and people!
It also helps to counterbalance the superhero's. "Could the world just stay saved for 10 minutes?" Is probably not unheard off, and your superhero's might decide they can do a better job at keeping the world safe unless there's some normies fighting alongside them. Normies that could use their tools to check up on those superhero's and see if they dont become the very villains they fight.
Guns have an inconvenient aspect, which is that they rely on bullets/ammunition. The contract of a gun is, "this explosive remains inert until and unless I press this button, at which point the explosive is very carefully detonated in a very controlled environment to accomplish a particular purpose.” They only work as long as this contract is satisfied.
Now, the bullet in the hole is a risk to whatever it happens to be pointed at; good gun etiquette says to never point a gun at anything you don’t want to destroy, even if you think you’re sure that it’s totally unloaded or uncocked or what-have-you. You just don’t take that risk. It’s hammered into you during training.
We did the same thing when fencing: your prevot (fencing teacher; I don't know all the levels) says “who are you fencing next?” and you point your foil at Roberto and say “Roberto” and suddenly your prevot has grabbed the foil wide-eyed and said “don’t you DARE point a sword at anyone who is not suited up” and you’re like “but, the rubber tip on the top” and he is like “NO EXCUSES. My master was such-and-so and his master was so-and-so and his master was so-and-so and his master was grandmaster Aldo i@#$%ng Nadi, and one thing I can tell you for absolute certain is that none of these people ever had a student poke out another student’s eyes, and I do not intend to be the first. Got it? Twenty pushups, now.” (Not that this ever happened to me or anything, heh.)
So a normal trained gun user will not be pointing guns at things that they do not want to destroy. But it still matters that this is how guns fundamentally work, you are carrying around a bunch of little explosives that are meant to accelerate death and you are assuming that the “rules” of the space are gonna be the same.
Several superpowers will make this inconvenient, all for the same basic reason. If the bullets all go off inside the magazine, I mean, probably the magazine stays intact and the bullets do not do too much damage, but at the very least the gun jams. The bullet in the hole could unexpectedly fire which is, y’know, not bad because it wasn’t pointed at anything, but also not good. Especially if the gun is holstered it could nick the leg or worse, maybe.
So you imagine someone has laser vision, that could certainly create a pocket of focused heat enough to replicate what the primer does. Lightning power might be able to target a spark just right inside the primer. Or pyrokinetics could do something similar. Sonic superpowers that head into ultrasound levels could replicate the sharp jab that the pin normally provides to the primer that starts the explosion. Telekinetics might be able to do the same thing, and they can do even worse: they can pull the trigger for you. Wrestling a sword away might be more force than they can muster, but pulling a trigger sounds more reasonable. For that matter, if you have it pointed at them, they might be able to enable the safety and thereby “disarm” you even if you are holding them at “point blank”, or perhaps it does not even need to be that overt, maybe they can stop the firing pin in its track or some similar action.
Or, vice versa, you have your gun pointed at some supervillain, you are like “it’s over for you, Sparky, you’re going to jail” and then suddenly your trigger gets pulled without your consent and Sparky is dead and off in the corner of your eye you see some damn telekinetic running off down an alley. Now you have two problems: several people “saw you” shoot Sparky without reason, and the actual person who pulled the trigger on him has a huge lead on you so it looks like you’re running away from the scene of a crime.
On the flip side, maybe you’re tracking someone with ice-based powers. What happens if they can freeze the gun so hard that the firing pin doesn't properly connect, or the primer is too cold to ignite or so? Could they fill the barrel with ice and misfire the thing that way? Do you really want to take that risk?
Swords are quite reliable. Even if someone has reality-warping powers so that they are not sharp, they’re still a reliable big club of steel you can beat someone in the head with. Clubs, even more so.
Why wouldn't a non-powered superhero use guns to improve their martial capabilities? There are many possible reasons, such as them being masters of non-firearm martial arts and such, but there's also a very good reason for why they might not use them that hasn't been addressed by other answers, and it's the reason why perhaps the most famous non-powered superhero, Batman, doesn't use guns: psychological trauma.
Batman doesn't use guns because a criminal used a gun to kill his parents, and that left him with the deep trauma that ultimately led to the anti-criminal vendetta that caused him to become the Batman in first place. As a result, he refused to use guns - if he uses a gun, it's a sign that he has become no better than the criminals he fights, and will shortly afterwards slide down the slippery slope of insanity and become a supervillain in his own right.
There are a multitude of legal precedents controlling and limiting the use of deadly force. I don't show them here because most are local laws governing police forces and I opted for an example at a national level.
However, it would be easy to research laws governing deadly force (for example, search for "California laws limiting use of deadly force") and to use any of those to craft the idea that since your non-powered (or powered) superheros are already honking powerful by virtue of their skills and technology, that they are forbidden to use firearms.
To simplify the precedent, limitations on deadly force exist because sometimes weaponry is too powerful for the situation and often cause more problems than they solve.
Therefore, I give you U.S. Code of Federal Regulations Title 10, Section 1047.7
§ 1047.7 Use of deadly force.
(a) Deadly force means that force which a reasonable person would consider likely to cause death or serious bodily harm. Its use may be justified only under conditions of extreme necessity, when all lesser means have failed or cannot reasonably be employed. A protective force officer is authorized to use deadly force only when one or more of the following circumstances exists:
(1) Self-Defense. When deadly force reasonably appears to be necessary to protect a protective force officer who reasonably believes himself or herself to be in imminent danger of death or serious bodily harm.
(2) Serious offenses against persons. When deadly force reasonably appears to be necessary to prevent the commission of a serious offense against a person(s) in circumstances presenting an imminent danger of death or serious bodily harm (e.g. sabotage of an occupied facility by explosives).
(3) Nuclear weapons or nuclear explosive devices. When deadly force reasonably appears to be necessary to prevent the theft, sabotage, or unauthorized control of a nuclear weapon or nuclear explosive device.
(4) Special nuclear material. When deadly force reasonably appears to be necessary to prevent the theft, sabotage, or unauthorized control of special nuclear material from an area of a fixed site or from a shipment where Category II or greater quantities are known or reasonably believed to be present.
(5) Apprehension. When deadly force reasonably appears to be necessary to apprehend or prevent the escape of a person reasonably believed to: (i) have committed an offense of the nature specified in paragraphs (a)(1) through (a)(4)1 of this section; or (ii) be escaping by use of a weapon or explosive or who otherwise indicates that he or she poses a significant threat of death or serious bodily harm to the protective force officer or others unless apprehended without delay.
1 These offenses are considered by the Department of Energy to pose a significant threat of death or serious bodily harm.
(b) Additional Considerations Involving Firearms. If it becomes necessary to use a firearm, the following precautions shall be observed:
(1) A warning, e.g. an order to halt, shall be given, if feasible, before a shot is fired.
(2) Warning shots shall not be fired.
I should note that most deadly force laws explain when deadly force CAN be used, not when it CAN'T be used. The assumption is that there are fewer reasons why it CAN be used than CAN'T.
One explanation that I like is that the supers are more effective with the melee weapons that you describe than they would be with guns. Imagine, for instance, that they could deflect bullets with swords (sort of the way that Jedi deflect blaster rounds with lightsabers). Then the sword might be a better option for supers, though a much worse one for people who are not nearly fast enough to use a sword in the way I describe.
For a more legality-oriented explanation: even though supers don't need guns, it still might be convenient to use them from time to time against regular people. Maybe it's easier to kill in mass, from a distance, etcetera, with guns than with a sword. The idea of some people using guns to kill others but being effectively impervious to them themselves is a concerning situation. I could see this being outlawed.
Edit: Note that deflecting bullets is just one example of how to make guns less practical for/against supers. Another might be that they just move so fast that they're hard to track, that they are so thick-skinned or well armored that bullets don't do much, some combination of those ... there are options.