The question is, should we be taking sides at all? Should we stick with the friend who has stuck by us through our own hard times/the friend who we've known since we were teeny tiny or stay neutral and sit on the fence?
This happened to me only yesterday, as a friend's ex boarded the train I was on. I tried to stay away but we made eye contact as we were leaving the train, and there was no turning back, I had to say something!
I should add that it was a pretty messy break up, but I didn't want to be rude and made general small talk without talking about the mentioned ex, and all was well.

To me taking sides seems a bit childish, although sometimes maybe it's acceptable (I'm thinking the Millie/Louise/Spencer scenario in Made In Chelsea here!). In a case of a friend's ex, steering clear when the break up is still a sore subject is probably your best bet - getting chummy with her ex while she's still in the practicing 'All by myself' Bridget Jones Style and eat my body weight in chocolate phrase might not be a good idea. But when they have both moved on and there's no awkwardness, simple small talk will stop you from being rude and anti social.
If it's a friend scenario, staying neutral will help to make sure you don't lose any friends. Just make sure a nasty friend doesn't start on you, or that you become the go between finding out what they're both saying about each other behind their backs. Also taking a side could come back to bite you in the future, if they make up and questions are raised as to why you stuck with one friend and not the other.