I know that spies return to the "pool" if one invades and captures the planet on which the spies are posted. However, there are a few wrinkles I have yet to be able to test.
1) If a planet changes hands due some transaction (bought, or traded for tech, etc.), do the spies go with the planet or return to the pool?
2) If a planet changes hands due to Jagged Knife?
3) What if it changes hands due to being "flipped"?
4) What if it changes hands because a DIFFERENT empire captured the planet?