If the AI has built a shipyard (btw, it looks like it is always using 1 planet per shipyard, never as much as possible (5) ) on a planet, and that planet is subsquently conquered or annexed, the shipyard will always stay behind. Sometimes, you get 2 or 3 shipyard orbiting a planet.
Imho, the shipyard should be dismantled by the AI when there is no chance it will get the planet back, like after a peace agreement, or destruction.
See ticket #PRG-440-79272 for a save game. It's been happening for a while