If you're losing the planet instantly, are you sure its a pirate raid? It sounds more like its the open rebellion random event from the Stellar Phenomenon DLC, which causes planets with low allegiance to revolt and spawn in a fleet of REBEL ships, not pirate ships. Check the name of the owner so we can be certain what you are experiencing.
If I'm correct, you need to raise the allegiance of the planets that are affected. You may also want to opt into the public beta of version 1.82 on steam, which makes this event less frequent, so that it can basically only be caused by enemy culture. As a last resort, you can start a new game with random events disabled.