Sometimes there's no other reason other than that they think they can get away with it at the time, so when an opportunity presents itself they'll take it.
Sometimes because they are genuinely having difficulty being in their relationship, but haven't yet got the courage to leave.
Sometimes, because they're not yet married - they want to keep their options opened.
Sometimes because they've caught up with someone they used to love - 'sex with the ex' kind of situation.
How you should react will depend on what kind of relationship you're in, and whether you're married, have children or are living together. As well as if you feel they may do it again. In any case you will feel hurt and you'll have to decide whether you want to continue the relationship with the 'cheater'.