Usually because I'm an idiot.
As a person grows older, it's harder to find lasting, dependable friends. The ones that will sit with you when your sick, the ones that laugh with you instead of at you, the ones that take you to the hospital on a Tuesday at 3AM after you OD'd on... wait, scratch that last one.
I tend to stay with my exes because there's a certain comfort and familiarity. It could be the emergency sex but it's also about the fact that this person had previously spent an enormous amount of time with you and invested emotionally, mentally, and physically in the relationship before it failed. Of the past four relationships, I've only had a clean break from one of them and that one was a total psychopath who stole a necktie and fountain pen. And drank my good wine.
That said, the friendship itself ends up being pretty unstable and prone to fail. But that's for another time.
Oh, and if they're attractive, I'm shallow and I like to be surrounded by pretty people.