Armed spacecraft have been around since the mid 21st century. The first civilian cargo freighters still had their original hull paint when someone bolted auto-cannons on the hull and attacked and boarded another ship. Soon after, rail guns and plasma cannons became factory add-ons. Of course, some governments moved in to curb the availability of such weapons to the general public. And as always, people ways to skirt (or break) those laws.
There are a few “outlaw shipyards” that operate way out in unregulated space. The most notorious is the Morningstar Shipyards in Free Port. However, there are at least a dozen others that are capable of building capital ships.
When unsanctioned warships started attacking cargo ships in the Outer Rim the Alliance and the Empire both started paying close attention to piracy.
An Alliance senator called them “a game changing threat to the outer rim.” An Imperial Admiral said “these bloody pirates are getting bloody hard to kill!”