First things first, let's just pretend the hyperspace ramming in the Last Jedi didn't happen, because hyperspace ramming means every FTL-capable vessel in the galaxy is a deadly weapon capable of destroying star destroyers, making this thread irrelevant.
Okay, so according to Wookieepedia, Han Solo won the Millennium Falcon gambling with Lando Calrissian. This explains how he was able to afford the ship. The Falcon is a YT-1300 Corellian Light freighter. Wookieepedia defines freighters as such:
A freighter, cargo ship, or barge was a kind of spacecraft used for hauling cargo from one place to another. Although light freighters could usually hold their own in combat against other fighter craft, larger vessels tended to be less capable. These large freighters could be easy targets considering their large size, slow speed, and weak armament. For this reason most heavy freighters required escorts when navigating more dangerous regions of the galaxy.
This is troubling; does this mean civilians are allowed to pilot spacecraft mounted with weapons capable of destroying other vessels? Spaceships can't be cheap, and I'm assuming Han has some sort of title and registration for the falcon, but in the real world most vehicles much bigger than an RV are owned by organizations, and in the case of naval vessels owned by shipping companies, merchant marines, or part of a country's fleet. With that comes all sorts of regulations, licensing fees, ID numbers, permits...
So what is Han Solo's official job title? We all know he's a smuggler, but that implies that his "official" job is something like cargo shipper or merchant. Or does he fly under the radar at all times, running from every authority he sees? What about other private vessels? Wookieepedia makes it clear that other freighters are allowed to have weapons mounted on their ships.
In the past during wartime private vessels were temporarily allowed to be mounted with weapons (relevant Wikipedia link), but that was an exceptional time (although granted the original trilogy does take many cues from WWII). Yes, armed guards with small arms are allowed, though expensive (Reddit, The Telegraph)... but ship-mounted weapons are a different story (Yahoo Answers, Quora). but what is the rationalization for a private spaceship like the Millennium Falcon being outfitted with weaponry capable of shooting down a pursuing fleet of Imperial Tie Fighters (the equivalent of fighter jets attacking a merchant freighter)? This "freighter" took out a Death Star for crying out loud.
My guess is it's allowed because of space pirates or the difficulty of maintaining law in the vast reaches of space, but then again, you'd think the Empire wouldn't allow much leeway considering their greatest threat is a massive covert rebellion and all. It seems like it would make more sense for freighters to be escorted or dangerous areas patrolled by the Empire.
I'm writing a sci-fi story of my own so it would be nice to know if there is a decent explanation other than "because it's cool." Example from sci-fi works other than Star Wars are welcome as well.