If memory serves, targeting an AI command station has a 50% chance of freeing all the defenders, and if they're not freed, starting to build a command station of your own has another 50% chance of freeing them. I read that ages ago so it might have since changed.
I normally take out all the defenders first. On higher difficulties, threat becomes a lot smarter. The freed ships are likely to dash away through a wormhole and eventually team up with the threatfleet, a potentially huge mobile AI fleet that will hang back from your worlds until it detects a weakness it can exploit. CPAs and the threatfleet are two of the more likely ways of losing at higher difficulty, at least in my experience.