Why do editors sometimes accept a paper even if a reviewer recommends rejection?
It is up to the editor whether to accept or reject. The reviewers only make recommendations. Even if the reviewers give positive recommendations, the editor can decide to reject a paper.
If both reviewers give negative recommendations, it is much less likely for the editor to accept a paper. If there is a mix of opinions the editor has to make a judgment, subject to whatever internal procedures the journal has in place. It seems like, this time, the decision was favorable for you.
To make sure I understand: you submitted a manuscript and got two referee reports. One of them was favorable (?) but the other one recommended rejection. Nevertheless you have been given the opportunity to revise the paper. I hope I got that right.
From the sound of it, the editor sees more merit in your paper than the second reviewer. I agree that when one review is positive and one is negative, rejection is the most common outcome. (I think the extent to which this happens is positively correlated with the reputation of the journal. Most of the journals I submit to are roughly in the "very good" range, and in that range they can and most often do only accept papers with uniformly positive feedback from reviewers.) However, that need not necessarily be the case: most frequent referees know of at least one example of a paper that appears notwithstanding the fact that they recommended rejection.
I would be wary of making changes that are (i) time-consuming and (ii) you do not agree actually improve the paper, because it is still by no means assured that the paper will be accepted by this journal in the end. However, if you agree with the suggestions and think the journal is very reputable: sure, make the changes, resubmit and hope for the best. Sometimes you catch a break: enjoy it.
The decision on a manuscript is usually based on more than one review, often two. As an editor you are faced with many different view from reviewers. Often reviews point in the same direction and may be differ by one providing a major revision and one a minor. But, it is no unheard of that one reviewer can suggest rejection while the other a direct accept.
In all cases, the editor should evaluate the reviews and arrive at some well-balanced decision for how the author should use the reviews to improve the manuscript (in addition, cases where MS are accepted without revisions are very, very rare; direct rejections are of course not so uncommon). If reviewers arrive at widely different recommendations and there are no obvious ways in which the editor can see how to reconcile the differing opinions, requesting an additional review by a third reviewer should be the solution. It is in this process where your question can appear because the way in which an editor values reviews depends on the scientific content, for one, but also on considerations such as the integrity of the journal and the publisher. Often such considerations lead to rejections rather than acceptance.
Accepting papers that have received more negative reviews can usually occur because the editor believes, for example, that the revisions suggested are not as severe as the reviewer indicated by suggesting (in your case) rejection, or, that the reviewer is off in the judgement as a whole. I have for example, seen rejection suggestions that are based more on antagonism than scientific reasons.
In the end reviewers make suggestions, editors (hopefully) provides an educated and insightful "verdict" that you need to adhere to in your revisions.
ad endum: When you receive more "extreme" negative reviews, you should ask yourself: is this because I am not very clear in some way? The answer is often yes!