I'd suggest a system similar to what exists in real life, owning small arms requires a license and even a permit, even with different license levels depending on the weapon. Sidearms might be fairly easy, but things like shotguns, assault rifles, explosives, etc, need higher licenses or are completely prohibited outside the military/security forces.
Producing small arms, legally, requires permission from the governing bodies of whichever station you are on. So Empire and Kingdom can determine costs for permission, as can large factions when they are implemented. People can still try to produce and own weapons without permission/license/permit/etc, but these become unregistered, unlicensed weapons. Anyone caught in possession of an unlicensed weapon then faces a penalty, whether this is confiscation, a fine, shot at on site, whatever, would be determined by the station.
If possible, make it an option for players in violation of a safe zone's laws to lose their protection. Thus making it possible for security to hunt them down, but they can't fight back. Hence very high risk to carry illegal weapons. Not sure if this loss of protection should be automatic, which could probably be abused (just shoot everyone in customs and the guy who gets hurt is breaking a law) or have it that a station admin could revoke protection. But this could also be abused, so... thoughts?
Actually looking for unlicensed weapons might require a specific item, like a hand held scanner that's linked to a database somewhere on the station. This checks player names with weapons they have a permit for, number of weapons, etc. This way, it would be possible to avoid detection of illegal weapons, but would also be risky.
Also, limit firearms manufacturing to stations. At least the more advanced firearms. Maybe basic things like pistols, assault rifles, shotguns and such could be produced on a ship, but more advanced weapons like energy weapons and explosives can only be made on a station.
Carrying weapons made and registered with one faction into a station owned by another would require treaties between those factions, customs, etc, or it would be illegal.
Also, make it a safe zone requirement to have some sort of firearms law in place.
This means that eventually, lawless stations may well eventually exist that don't enforce any laws for firearms, but these would have to be outside the safe zones, and so would be extremely risky to do business at. This is where black markets would thrive, but reputable merchants and traders would avoid, because of the risk of being jumped, killed, and losing their haul.
While I'm sure this system would take a lot of work, and will still have problems, it will at least allow:
-Enforced gun control within safe zones, where the majority of commerce will probably happen.
-Diplomacy between factions for the transport of goods, especially things like firearms.
-Regulations for producing and owning firearms, with more dangerous firearms requiring harder to obtain permissions.
-The existence of high risk, lawless stations (eventually) where black markets can thrive.
-Customs for arrival at stations belonging to a faction that you are not part of. This would require players to work at, but could eventually be replaced with YOLOL based on inventory or even NPCs if those are added.