The thing about being a pirate is that you have a job to do, that being pirating stuff. There are two things that a successful pirate needs:
- A place where marks are going with goods that could be successfully pirated.
- A place where pirates can sell said goods without too many questions asked.
So for pirates to raid trading posts, they risk biting the hand that feeds them - I mean obviously we are dealing with scummy space bandits here who are out to steal everything that they can, but the smart pirate is going to want to have a sustainable business model that offers them the most possible profit for the least risk. That means that you pick up on shipping, but you probably leave trading ports well alone because you actually want to have agents in them telling you about shipments coming and going and helping you to fence goods that you have purloined. If you turn an entire station over, then you have a good chance of harming your own people or reducing a potential source of revenue.
The consequence is that pirates and shadow economy traders are going to need those trading posts as much as anybody else and they are going to benefit from a certain status-quo where no trading post gets too powerful or able to make stronger demands but in the case of an outside raid on a planet's periphery stations, you are likely to see an unlikely alliance of local criminals, local law makers and the stations themselves banding together to protect their local power base.
Criminal organisations' interests do not necessarily stand against everyone else's - look at the role of the Mafia in WW2 - and competent criminals, the ones sufficiently resourceful to have control of ships capable of causing serious trouble to a trading post, are likely to be rational about matters of business and income.
Edit: It occurs to me on rereading this that one of the important things for your trading posts is that they don't need to be objectively tough, they need to be relatively high risk targets. So if a potential raider looks at your trading post and the other trading posts and the traffic coming into and going out of the trading posts, they need to see that a raid on your trading post is going to be a bigger risk than a raid on others. It is less about being a hard target and more about being less of an easy target.