(local) Overpopulation
Population grows fast and Earth is space limited. Moreover majority lives in cities, so space is scarity and population density is going insane. If you remember old japanese houses, they was literally just wooden skeleton and paper walls. Now it is like high-tech skeleton and cheap plastic walls, doors and floorings. The walls can be cut with sharp knife (sometime even jumped thru, if older and a lot of force is used) and fixed with a glue or tape or spare plastic. The floorings is double layered, so it is somehow more rigid, but still not fully. But hey, it is cheap and you will get acustomed. Such building may have many tens or few hundreds of floors (like WTC) each about few km^2 big and incorporate streets, shops, restaurants, everything. If you are poor (as majority is) then you live in some such building-city.
Cosmical traveling is possible, but expensive in term of energy (gravitation well), so while there is a lot of ships in space and they bring lot of materials, still there is need to so much Earth based work and only few people from millions will get out of Earth - the rest is working, so it is even possible. Need to say, that big space stations are overcrowded as well. (Also look for Apollo, how much space there was for crew).
So the result is, that there are many rich people and even more well doing and those lives in decent houses or even palaces.
But it is just drop in ocean of relatively poor masses. And those masses are not exactly happy and loyal, but thanks to many social engeneering are not (yet) directly hostile and rebelious. Mainly. There is none simple way to make everybody happy, so the powers try to keep status quo. There is massive police (and corporate armies, and security agencies) to keep some kind of order, but small misconductions are generally overlooked, so those overcrowed enclaves are (illegaly) modified, new doors, shop windows, ways etc. are made (and undocumented) on daily base, but fixing it would mean to imprisoned too many people and starting Rebelion now - so it is more or less tolerated. (anyway, who cares...).
There is a lot of rebelious types, who mainly call themself Resistance (but they are mainly local, each group with little different ideas, from global revolution to pub-talking and small sabotages/vandalism). People tolerate their actions mainly because the police is not able effectively stop it and nobody likes police. Also Resistance is komonly known for doing only small property damage to normal people and usually repair it later (like cutting thru walls on escape route and later bring lot of glue and whisky) as long, as nobody resist them. And they lives near and knows you, so you rather look other way, "I was scared, so I could not do nothing", "I do not remember nothing", "I did not seen them before" and so on,if the damned police asks you about them.
The police is ofcourse protected by relatively good armor (say like todays SWAT), which can stop one or two shots or knife and walk to enclaves in squats of at least 4-8 man, armed with anything they want. But riffle can kill bystander over 8 walls away, if it miss target and 2 walls away, if it hits unarmed target. And it is not good.
You kill too many civilian or some more popular and you are fighting few hundred relatives next moment and get slow killed just by being repeatedly hitted by crowbars, full bottles and any other mundane weapons, while other ten rebels are sitting on your hands and legs. (And then stripped from the armor and robbed of your guns.) On the other way the Resistance member may have some armor too (stolen or improvised from iron plates), so wall-safe ammo may not be able to hit them effectively.
So you have some buttons too, as it is relatively effective and safe to use - you see, who/what you are hitting and few scratches on innoncent does mean nothing with the courts on your side.
Problem is, that without armor you are vulnerable to anything (and some rebels may be armed) and with better armor you sacrifice mobility - and it targer get like 5-10 room distance, it is effectively lost and safe for today. So you will choose "adequate" armor, not the "best", even if you had money for that. And you choose handguns rather then automatic riffles, for your own safety - court may release you, but angry mass can kill you without court intervention. And soon you will have not only buttons to free your way and subdue opponents, but also swords, sabres or so, which aneable you to make fast "shortcuts" too and use killing force on armed enemy effectively, without risking too much collateral deaths.
The Resistance have similar problems - you do not want kill or hurt locals, because without their help (or at least tolerance) you are done. You need mobility more then armor, so you use only some light versions. But swords and other melee weapons are good for opening "shortcuts" eve thhere, where you do not know any and if you use civil clothes, you can avoid police at all, or at least approach them undetected, as part of usual street mass, if you want to attack. And the attack will probably take place from distance zero, with surprice, but with too much locals around, who you do not want hurt.
Sending military in make no sence, as there would be need too many of them, fight on full with and height of the megabuilding, most of Resistance would pretend normal people and those really wanted can literally cut their way not thru your units, but thru the walls, ceilings, technical sections ... and run away anyway. But after sending full military in you can expect the Revolution immediatelly and loose any legitimity, as you send army agains nearly all of your nation.
Result
Ranged weapons and heavy armor are good for battle, but not for policing megacities (except few exceptions), melee weapons and light armors are much more practical for majority of internal forces.
If there would be war with other nation, tanks, bombers, cannons, snipers and all the rest of clasical army up to aircraft carriers is good for getting fields and strategical points, but to get megacities, you still need clasical light armor/melee weapon police and good propaganda. (Also any smaler unit could use melee weapons for getting pass thru civilian places to next military assignment - like secretly place sniper, or anticraft missiles on the roof, or eliminate enemy sniper placed there) And you need the population to work for you, after all. You fight for resources, money and control, not for national hatred/pride or something like that (regardless what you make media tell).
And the police would have way more man than army, so here you have your melee needs.