If you immigrate by being petitioned by a US citizen or permanent resident, and you have been married for less than 2 years on the date you become a permanent resident, you will become a conditional permanent resident with a 2-year green card, and you will have to apply for Removal of Conditions. If you have been married for more than 2 years on the date you become a permanent resident, you will become a non-conditional permanent resident with a 10-year green card.
If you divorce before you become a permanent resident, you cannot become a permanent resident on the basis of your ex-spouse's petition anymore.
If your marriage was (and you can show that it was) bona fide (i.e. it was not entered into to circumvent the immigration laws), but later falls apart and you divorce at any time after you become a permanent resident, you can keep your green card. This is true no matter if you are a conditional or non-conditional permanent resident at the time you divorce. If you are a conditional permanent resident, you can apply for Removal of Conditions by yourself on the basis that the marriage ended in divorce. (Of course, in that case, you can expect extra scrutiny regarding whether your marriage was bona fide).
If your marriage is fraudulent (i.e. entered into in order to circumvent the immigration laws), any status you obtained through it can be revoked when this is found out. This is true no matter if you become a conditional or non-conditional permanent resident, and no matter how long after you get your green card before you divorce (or even if you do not divorce). And even if you go through the naturalization process to supposedly become a US citizen, that naturalization can still be revoked if it is found that there was fraud in any part of your immigration process.