See, there is a good way and a bad way to role playing to detriment. The bad way is role playing to the detriment of the fun of the game and the other players. The good way is role playing to the detriment of the character. There is also a third way, which I will touch on in the end, and that I can't limit to simply saying it is bad, because in fact it is dangerous. That third way? Role Playing to the Detriment of the Player.
Role Playing to the Detriment of the Group
So, you've probably seen this at some point in time during your role playing career. Everyone is starting to get into the plot, and then someone decides to go off on their own and do something completely different. They don't share the vital information, they hold back on key things to the games progression. They are essentially fighting, kicking and screaming, the progression of the plot. There defense to it? "My character would do that"
This is role playing to the detriment of the group. See, the person in question is killing the fun for the other plays with their character. It isn't always done intentionally, but it can be infuriating to experience as a GM or one of the players who is being stepped on by a person doing this. Once it has begun happening though, there is only one way to stop it, and that is to talk to the player in question. Point out that they are killing the fun for everyone in the game, and ask them to stop or reign it in a little. Games are supposed to be fun after all, and if the person is your friend they probably don't want to annoy you. But they won't know they are unless you tell them.
As a player, the way to stop yourself from doing this is actually rather simple. When you make your character, even if you want to be the bad ass loner, give yourself a reason to be working with the group. To want to succeed with the group. Talk to the GM about it if you're unsure how to do it on your own, but you need a reason to work with the group. This ensures that you aren't stepping on people, and should help stopping you from hitting those areas where you are standing in direct opposition to the flow of the plot constantly and consistently because that is what your character would do. If you ever find yourself regularly doing just that, make sure the other players and GMs are ok with it. If people aren't having fun, maybe see about modifying your actions, but if everyone is having fun and no one is complaining (especially when you ask them) then keep on keeping on.
Role Playing to the Detriment of the Character
As a GM I absolutely love it when players do this. What is it exactly? It is role playing in a way that brings about fun for the entire game by essentially throwing your own character under the bus. It is walking into that warehouse where your enemy is set up to ambush you, because your character would. It is punching out that General because he's the guy responsible for killing your father, and that is what your character would do. It is swallowing your pride and trusting that girl for the fifth time even though she is probably going to back stab you again, because that is what your character would do.
Essentially, this is welcoming complication into the game for your character because the actions that cause it are what your character would do. You aren't making the sound tactical choices that you, the player, know are the best way through the scenario because your character isn't you. They're not privy to all that extra knowledge you have, including the most crucial piece of all "this is a game". You keep that separate, do what your character would do, and play through the mishaps that happen.
The key difference between this, and to the detriment of the group, is that doing this adds fun to the group, where as to the detriment of the group is taking that fun away. You need to judge when it is one and not the other, but everyone will appreciate it and the story opportunities it can bring when you do get it right.
Role Playing to the Detriment of the Player
Or in other words being too in character. This happens on occasion with people, they get way too attached to their character. The lines between the character and the player begins to blur, insults given to the character get taken as insults to the player. It is just in general a bad place to be, and you want to be careful if you, or someone in your group begins to show signs of it.
Playing a character can be a lot of fun, and it can be a real ride when you really get into it and are doing things that feel right for the character though you don't know why. However, you also need to have a healthy level of separation from your character. The thought of bad things happening to your character shouldn't make you feel depressed or anxious out of the game. Game, that is all it is. You are telling a story and having fun. If your character is messing with your head space so much that you can't break out of it, or it is bringing anxiety or stress to your everyday life you need to take a break from it.
I've mentioned this before here, but Games can be powerful things. I know people who have had players start exhibiting PTSD like symptoms. I have accidentally given players nightmares for weeks. In both cases part of the cause was that the players were too far in character, they couldn't put the game down.
Some other signs, more common online, is that the death of the character, or bad things happening to the character, actually makes the player cry. As I said, this happens more online than at table top, because online you really connect and play the character more. However, it is also a sign of a potentially unhealthy connection with the character, and may be a sign that you really need to take a step back and create some space between you and the game.
As said numerous times, games are meant to be fun. RPGs are games. Therefore, RPGs are meant to be fun. If you aren't having fun, you need to find a way to fix that.