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.