Keeping valid shares for it's own when mining in a pool
The address the block reward goes to is in the data that is being hashed. That address is the pool's. If a miner finds a hash that meets the block difficulty, changing the address to the miner's own will cause a different hash, and you don't have control over the distribution of the bits in that second hash. So you don't get a block if you change the address.

Going the other way is the same: if the miner mines using his or her own address, that miner will not be able to send shares to the pool to secure part of next block the pool finds.

A miner can withhold the winning share though, which is detrimental to the pool, but cannot pocket the reward.