Beyond sentimental and cultural reasons, of which you can build many and include, here are some practical reasons in a high-science setting.
In the TARDIS on Doctor Who (talking old Who here, think it lost this in New Who), he was able to turn on a peace shield that prevented firearms and laser weapons from working. This did not apply to more primitive weapons that didn't use combustion or high tech stuff. So anyone with a bow and arrow, knife, or sword was still deadly.
Low Tech Zones
Just like peace shields, but this might be naturally occurring, and it would not just apply to weaponry. There may be areas where all tech doesn't work properly. Once you've crossed over into one of these areas, all your tech and your guns just won't go. (I haven't given you a reason why, because there's whole range of imagination you can use for this--to keep certain people corralled and limited if it's not naturally occurring, to disruptive EM waves that render laser weapons inert.)
Tech and Primitive Hybrid
Your primitive weapon may have a hidden talent. It looks like a sword and can be used in places where guns aren't allowed (or there is something like a peace shield), but it can also fire pulses. Maybe it uses the action of the sword as stored energy. The pulses can knock the enemy down, actually harm them or...and this is sneaky, actually disable anything high tech. Also, the sword can have some sort of shield against ranged weapons over a certain velocity. You could even have the weapon be strengthened by the kinetic energy, using some crazy somewhat hand-waving science.
Guns are used, however, there's a sophisticated tracking system in place. All weapons have a specific signature and any weapon fired brings the law rather instantaneously or barriers come down, trapping/containing the person until they can be arrested--and/or some kind of gas is used to knock out everyone in the area. (Maybe they have teleporters for law enforcement). If someone fires a weapon, they are going to make tracks just after. They might have a gun, but they only use it as a last resort because they know they will be caught immediately. Weapons such as swords are not tracked this way, so most criminals end up using bows, arrows and knives.
Swords vs. Guns
A gun is superior to a sword, in that someone with no training and a gun can kill a lot of people. Swords take skill. That you are putting a sword against guns makes the odds against the protagonist more stacked, so he'd going to have to fight smart and stealthy. People with guns don't expect someone to come up to them and disarm them. Your guy will get shot. I'd say armor or some kind of shielding would be a good idea.