There are as many reasons as there are people who have affairs, I suppose. But a few I have encountered (in friends, partners, family members etc):
Unhappy in the relationship and wanting to leave it but scared to say so so they back themselves into a corner with the affair.
Feeling an aspect of their sexuality (BDSM for example) not met on their marriage.
Suspect their spouse of cheating - revenge affair.
Fall in love with someone else when already married. Doesn't always mean they have stopped loving their spouse. The married man who tried to have an affair with me when I was at a very low ebb (dd's dad had been cheating and I had finally left him) claimed, I think with sincerity, that he loved me, though he was open about the fact that he still loved his wife, and would never leave her. I turned him down, though I was very attracted and in some ways liked him a lot.
Spouse choosing not to or unable to have sex due to health reasons, age etc.
Error of judgement under the influence of alcohol or drugs (that would be more a one night stand than an on-going affair).
I could go on......
I don't agree that affairs are always as bad as they are made out to be on here - almost tantamount to rape or murder. I think some affairs are worse than others, but fundamentally nobody belongs to anyone. I do agree that lying is generally bad, though I also think very few people are entirely honest at all times. (Including with themselves).