I play the Devil's Advocate all the time, I think with a good amount of success (as in, people don't usually get made at me for it). There are a few things I always keep in mind.
When you should do it
If you know that the person you're talking to appreciates open discourses on contentious subjects.
There are some people who do not want their worldview challenged. For those people, do not challenge it. However, there are some people who simply want to find the root of an issue. They're willing to forgo political affiliations in exchange for objectivity. These are the types of people you play the Devil's Advocate with.
If you know both sides of the debate
Further, you shouldn't play the Devil's Advocate on an issue you're not too familiar with. The whole point is to open up a discourse, but if you don't know how each side fits into the other (or, more appropriately, how they don't), then you're just arguing. They'll say their side, you'll present the alternative, and that's that. Nobody like that. Don't do that.
How to approach it
Remove your own opinions from the conversation. Completely.
When playing the Devil's Advocate, you have to remember that you aren't expressing your own opinion. Rather, you're communicating the Devil's opinion. By definition, the Devil's opinion is not favorable, so you have to make absolutely sure that you don't accidentally conflate that opinion with your own. That's one of the reasons it's so important to know both sides of the debate. If you enter the conversation with only one side, you'll find it very difficult not to give a bias towards that side. Once you stop approaching the conversation objectively, you're not playing the Devil's Advocate anymore. If you find yourself too emotionally attached to one side, don't play the Devil's Advocate. It won't work.
Never present these arguments as your own.
This one's a little tough, but you have to keep the person you're talking to from thinking you endorse the Devil's opinion, even if you do. I do this by explicitly stating someone else holds this opinion. For example, if you say "when Y happens it leads to Z", and someone disagrees, they're arguing with you. If you say "conservatives think that Y leads to Z", and someone disagrees, they're arguing with the idea. I've found when people push back on the former phrasing, they're expecting me to defend that stance, and if I oblige I find myself entrenched on that side. We're trying to avoid that. When people push back on the latter phrasing, they're typically expecting me to explain why the other side thinks that. This keeps me nicely detached from either side, keeps things objective, and lets me just shrug if the other person seems too upset.
Try to present both sides equally
If you end up presenting the liberal stance on every issue, you're not the Devil's Advocate; you're the Liberal's Advocate. Now you're not objective anymore. Further, by only presenting an opposing position, the person you're talking to is going to slip into that mindset that you agree with the Devil. Avoid that. Don't be afraid to counter the arguments you bring up with arguments from the other side (another reason to know both sides). This reinforces the perception that you're just trying to keep an open and objective discourse. If you only argue one way, people will forget that.
When to stop
The other person gets too fired up
Remember when I said not to play the Devil's Advocate if you're too attached to one side? That applies for the person you're talking to as well. If I told someone I supported vaccinations and they tried to play the Devil's Advocate, I'd get mad at them no matter how far they try to separate their own opinions and the opinions they're sharing. That's one of those topics I cannot approach civilly. If you realize you've stepped into one of those topics, stop.
You aren't certain about what you're talking about
Remember the whole point here is to discuss both sides of a topic. If you find yourself speculating too much, you aren't representing the other side very well anymore. Further, the bigger the gaps in your knowledge, the more you'll find yourself filling those gaps with personal opinions. We've gone over why this should be avoided.
An example's been requested
My wife and I were talking about the "Right to Try" bill recently passed in the US. It states that terminally ill patients can try non-FDA approved medicines now. That's an overgeneralization, but it's close. My wife says:
How could everyone not support this? If someone's dying why not let them try anything?
Personally, I agree, but I'm actually familiar with some of this debate. Further, I know my wife. I'm aware she'd be open to discussion, assuming I don't push it too far.
I replied along the lines of:
Well, a lot of critics are concerned that sick people will try the non-FDA drugs first because they're less expensive. Since those drugs are also less likely to work, that might cause avoidable deaths. They think it should only be an option after trying the FDA-approved options. Of course, drug manufacturers could just game that by saying their regimen takes a year or something to run its course so people don't get to try anything else anyway.
Here I've presented an opposing stance (as someone else's), but also brought up a flaw in it as well. Hopefully, that response shouldn't tip my own hand. Further, I know there's an argument to be made about lowering drug prices, but I don't know it, so I didn't make it. Also, if my wife had a terminally ill family member, I'd never touch this issue. I would be too personal, too emotional, and would just cause trouble.