Canon law on the subject is complicated, but to break it down to it’s simplest form a marriage is valid when both parties, at the time of their wedding, freely and with full understanding consent to marriage as taught by the Church. The couple both have to understand that marriage is permanent (cannot be dissolved by divorce), for the procreation and rearing of children (open to life), exclusive (no cheating or open marriage agreements), and for the good of the spouses (mutual aid). There can be no fear or coersion, no fraud, no conditions, etc.
Nothing can invalidate a marriage validly entered into at the time of the ceremony, but what happens after the ceremony can be used as evidence that there was something wrong from the beginning.
The annulment process is not simple. First, a petitioner consults their pastor to see if they even have grounds. Then they begin to work with a Procurator-Advocate to fill out the required paperwork and gather evidence including Witness testimony, counseling reports, arrest records and hospital records pertaining to the marriage, etc.
Once the paperwork if filled out and evidence gathered, everything is reviewed by the local Tribunal. The Procurator-Advocate writes up a summary explaining why the marriage should be declared invalid. A Defender of the Bond writes up a statement explaining why s/he believes the marriage to have been valid. A Judge reads the evidence and those statements and makes a determination.
Once the Court of First Instance Judge has made his/her determination the case is sent to another Tribunal, called the Court of Second Instance, for review. If both courts agree the marriage was invalid, the Decree of Nullity is granted. If both believe the marriage was valid, a decree is not granted and the parties can appeal. If one court believes the marriage to have been invalid and the other believes the marriage was valid, the case is sent to Rome for a determination.
This is not a “rubber stamp” process.
The examples you gave are pretty common.
If one spouse was having an affair when the marriage took place that could be grounds for nullity. Obviously, he or she didn’t place much value on exclusivity. Without the situation being disclosed to the other party, how could that party freely consent to the marriage? If one party conceals something in order to get the other party to consent to marriage it is fraud. If the affair ended after the wedding the marriage would still be invalid because A) exclusivity and B) the other party still couldn’t freely consent to marriage without knowing something of that magnitude.
Contraception doesn’t necessarily make a marriage invalid, but it could. If the contracepting party had no intention of being open to children than the marriage would be invalid. If the contracepting party intended to have children later than the marriage would be valid. If the party contracepting went into the marriage with the sincere intention of having children and later changed their mind, that would seem to be a pretty gray area and above my pay grade.
Abusiveness and mental illnesses effect consent for both parties. An abusive person is mentally ill. Mental illness calls into question both the ability to consent to marriage and the ability to fulfill the duties and obligations of marriage.
As for the example of the person who had an annulment denied because they consented properly on their wedding day and then one changed their mind about children later, the marriage was probably validly entered into. If it was not validly entered into, perhaps there wasn’t enough evidence available for the Tribunal to declare the marriage null.
Hope I helped