Another definition of the phrase on Urban Dictionary attributes the phrase, in its sarcastic usage, at least, to Bob, a sitcom starring Bob Newhart as a psychiatrist. While I hesitate to take this particular uncited claim to be a definitive proof, it seems to me to at least be representative of the most logical reason as to how the seemingly innocuous phrase would take root in our culture in such a sarcastic way.
The phrase likely originated in a psychological context as an attempt by psychologists and group-therapists to help provide validity to the personal experience of patients, and to encourage them to keep talking about and sharing their problems.
"Thank you for sharing (your story)!"
This particular usage has also been picked up by some teachers, especially teachers of the humanities, to encourage people to develop their own opinions and have their own voice, on the basis that "no opinion is wrong".
"Thank you for sharing (your opinion)!"
This phrase may also be used (by a much different teacher) as an attempt to move on and avoid giving a particularly controversial (or possibly "crazy") perspective much class time, in which case the phrase would generally be followed by a new question regarding the same topic or an immediate topic change.
Both fields in their modern form find themselves under much scrutiny (deserved or otherwise) for their supposed pandering to individuals' feelings of entitlement and the need to be viewed as "special", and so, unfortunately, often the younger, less-experienced professionals in the fields of psychology and education are stereotyped as the archetypal camp counselor who refuses to be sad and refuses to let anyone else be sad because we are all special snowflakes in our own way!
Outside of those fields, however, the phrase is unlikely to be heard in any serious context; the more common usage, definitively, is a sarcastic one. This stems from the fact that a large number of people believe that some opinions and some experiences are better left unsaid, or that some opinions are blatantly false and not worth arguing.
One relatively common example of the phrase's use is as a way for an individual to point out to another individual that the information they have shared is exceedingly inappropriate to be sharing with the present audience.
"I have had diarrhea all week!"
"Thanks for sharing."
Similarly, the phrase can also be used as a response to a statement which is believed to be boring or irrelevent to anyone aside from the one who made the statement. An individual using the phrase in this particular situation is expressing his or her lack of interest in the topic, or, more specifically, lack of interest in discussing the topic.
"Sometimes, when my dog howls, it sounds like he's saying 'hello!'"
"Thanks for sharing."
Often, the statement in question is relevant to a conversation, but random enough to risk derailing it, and so the phrase is used in an attempt to dismiss the comment made and carry on with the (theoretically more important) ongoing discussion.
"... Yeah, it'll be interesting to see how the situation in Russia will play out."
"Oh my God, I just saw the cutest Russian doll the other day..."
"Thanks for sharing. Anyways, I think we should..."
The above examples seem to be the most common day-to-day usages. The phrase is a way for an individual to dismissively remind another individual that he or she is not, in fact, that person's therapist (mocking the psychological field). It follows the line of logic, more or less, that the speaker would need to pay the individual using the phrase (as a therapist) for that individual to shoulder the burden of listening to them. The individual is attempting to remind the speaker that here, in the real world, not every thought or fact is intrinsically valuable, and so not every thought or fact is worth sharing. The third example, in particular, also can have ties to the educational field, as it is often an attempt to ensure that the conversation stays more or less "academic" (or, at the very least, "serious") in nature.
However, as is growing increasingly common in the vernacular of America's youth, the phrase can also be used in the context of an argument to dismiss a perspective or opinion deemed by to be lacking intellectual merit, due to devil's advocacy or due to a disconnection from reality (in the opinion of the individual using the phrase), and therefore deemed unworthy of consideration or response (mocking the educational field). This phrase is usually used, in this usage, before the originally speaker has a chance to back up his or her claim, in order to avoid a lengthy and "pointless" argument.
"Evolution is a myth."
"Thanks for sharing."
The main idea in both of these usages is that everyone present would probably be a whole lot better off if the speaker had not shared with the group what they just said, in stark contrast to the use of the phrase in a more psychologically therapeutic (or intellectually "open") setting.