Compression is no different than any other signal processing tool like EQ or reverb:
Use compression where it's needed, don't use it where it isn't needed. This is true in all three phases of recording; tracking, mixing and mastering.
In GENERAL:
Tracking: If you need to compress on the way in to the control room to tame the dynamic range well enough to get manageable signal levels, then do so. Otherwise save the compression for if/when iit's needed later for mixing or effect.
Mixing: If you need to compress individual tracks or submixes in order to get them to "sit better" in the mix with the other tracks - and compression gives a more desireable result in this case than automation - then compress those tracks to taste for the purpose of getting the mix.
Additionally, it's at this stage where you'd apply any individual compression to individual tracks or groups for special audio effect.
(Pre)Mastering: If you need to compress to boost the overall RMS volume of the mix, this is where it would usually be done.
It's also important to note that these three steps do not exist in their own worlds but instead interact with each other in unavoidable ways. For instance, compression during the tracking stage will affect your range of options in the mixing stage, and compression in the mixing stage will often have the same effect on your options in premastering.
G.