Mary Sue is a term in use primarily in Fan Fic circles to describe a particular type of character. This much everyone can agree on. What that character type is, exactly, differs wildly from circle to circle, and often from person to person.
TV Tropes Wiki doesn't get to set what the term means. The best we can do is capture the way it is used.
The closest thing to any sort of definition is of a character that has too many positive characteristics, and any readily apparent flaws are not relevant to the story. Despite what many tongue-in-cheek litmus tests claim, there isn't any way to measure what "too many" positive characteristics might mean.
The name comes from the 1974 Star Trekfanfic "A Trekkie's Tale".
More:
Originally written as a parody of the standard Self Insert Fic of the time (as opposed to any particular traits), the name was quickly adopted by the Star Trek fanfiction community. Its original meaning mostly held that it was an Always FemaleAuthor Avatar, regardless of character role or perceived quality. Often, said characters would get in a relationship with either Kirk or Spock, turn out to have a familial bond with a crew member, be a Half Human Hybrid masquerading as a human, and/or die in a graceful, beautiful way to reinforce that the character was Too Good For This Sinful Earth. Even back then, there wasn't a total consensus on what was or wasn't Mary Sue, since it's not always immediately obvious which character is an Author Avatar.
Over time, a male variant started to see use. Marty Stu (also known as Gary Stu depending on preference) wasn't really that much different from Mary. Also an Author Avatar, it usually had implications of being more of a male crew member that tended to completely outshine established canon members in their roles and often become the best starship captain ever. See The Ace. Since the female characters of Star Trek were all in secondary roles at best, the relationship angle was generally disregarded as being any sort of qualifier. Because of the not-entirely-unjustified perception that Most Fanfic Writers Are Girls, Marty Stu didn't really catch on for a long time.
The term used to be exclusively about fanfiction around the time of Star Trek: The Next Generation, when Canon Sue started seeing use. Most likely inspired by the backlash against Wesley Crusher, it originally applied the same Author Avatar standard to canon works. It was around this time that the term started to lose a concrete meaning, since the label started getting applied even to characters that weren't explicit self-inserts (such as the title character of the episode "The Empath") simply because they used similar tropes. It was most likely around this time of that the term started to gain its pejorative tone.
The advent of the internet allowed the term to migrate out of the Star Trek community to most fandoms, losing pretty much any real meaning in the process. There are dozens upon dozens of essays that offer interpretations of what the term means, generally basing it off of some usages of it, but none of them are truly comprehensive or accepted. In truth, the closest thing to a consensus on a definition is that it is bad. Using the term in most contexts isn't too far off from Flame Bait, generally provoking the defendant into rants. Much Internet Backdraft has resulted, especially if the term is applied to a canon character on a popular show.
See these articles for takes on Mary Sue that focus on certain groupings of Common Mary Sue Traits:
A couple of systems have popped up to classify Mary Sue characters, the most popular of which is a variation on the Characterization Tags system. For example, a Perky Goth sorceress that is also a dragon might be labeled as Goth!Sorceress!Dragon!Sue. Alternatively, something might just be referred to as (insert biggest trait here)-Sue, but that doesn't allow for a whole lot of elements to be tacked on. There are also a couple of tests in the Internet to quickly determine if a character is overdosed with Common Mary Sue Traits (maybe with a couple pointers on underlying Sue structure); you can find most of them by searching for "mary sue litmus test".
See Common Mary Sue Traits for the superficial tropes that get involved in a lot of Mary Sue fiction, but are not immediately evocative of it. Also see Marty Stu, which looks at both this and Common Mary Sue Traits from a male perspective. For a short explanation of non-fanfiction Mary Sue characters, see Canon Sue. See also Possession Sue (when an existing canon character is derailed towards this) and Copy Cat Sue (when a character is a blatant copy of a canon character). See Mary Sue Classic for the extremely common plot framework that the character often uses. Finally, for characters that often evoke this trope (but may not actually be proper entries within it), see Magical Girlfriend, Yamato Nadeshiko, A God Am I, Mac Guffin Girl, and Author Created Character.
Interpretations of Mary Sue
As mentioned above, there are many interpretations of what does or doesn't constitute a Mary Sue. In this sense, Mary Sue isn't so much a trope as it is a brand name, with the usage being determined by both writer and reader. It is not limited in usage, getting applied to all characters regardless of gender, role, or species. Sometimes, even whole groups, organizations, and even societies are labeled as being Mary Sue. This is a list of some of the interpretations. They are here to offer insight into why people might call a character a Mary Sue.
Mary Sue as Protagonist You Don't Like:
The majority use of the term and much of the reason that it has lost its meaning. While it might seem like it's just Flame Bait, this interpretation came about mostly because of the counter-Sue interpretation that "a character is not a Mary Sue if you like them". Sometimes, attempts at justification are given in this, but they often revolve around shoehorning, Alternate Character Interpretation, misrepresenting the sources, and Accentuate The Negative. This invocation is almost always brought up with the Canon Sue label.
Mary Sue as Poorly Written Character:
Related to the above, this interpretation posits that a Mary Sue is simply a character that breaks Willing Suspension Of Disbelief due to carrying improbable, contradictory, and even paradoxical elements while being written in an inconsistent manner. It should be noted that almost no writers intentionally do this and will usually make the same sort of mistakes with other characters as well, but due to Character Focus, one character will tend to gather more of these than the others. Generally only gets thrown around in fanfiction due to the baseline of the story being different from the source.
Mary Sue as Author Avatar:
Simple as that. The original meaning, this one has lost prominence as a sole definition lately but still often gets invoked. People used to sometimes call their Alter Ego characters "their Mary Sue", but this usage has pretty much died with the proliferation of the term as an automatic pejorative.
Mary Sue as Idealized Character:
The interpretation that Mary Sue is a character that is idealized to a fault. A very influential interpretation, this one tends to get applied to most discussions. This theory posits that a Mary Sue is an unrealistically optimistic character, one that simply lacks flaws and is shown in an overly positive light. This tends to draw the most debate as this model of character extremely common and also a lot more accepted than people give it credit for. Charles Dickens, one of the established classic authors, used to specialize in creating characters like this. A lot of characters in both male- and female-centric fiction simply lack meaningful flaws, but are more than accepted because they work as Escapism for the audience.
However, both this interpretation and a shift of society as a whole towards cynicism has lead to many people trying to mask their otherwise idealized characters with either total non-flaws (e.g. being So Beautiful, It's A Curse and other Cursed With Awesome details), flaws by proxy (e.g. Dark And Troubled Past), or flaws that simply don't play any role in the plot at all (e.g. making a character an alcoholic, but never showing them as impeded by it). Often, this leads to a particular extreme where people start treating flaws themselves as Character Development and create a character that simply has no merits outside of being able to do the most basic biological functions (Anti Sue).
Mary Sue as Power Fantasy:
The other influential interpretation, this one posits that a Mary Sue is a character that exists to provide a satisfying fantasy for its author. It should be noted that this type is a widely accepted form of storytelling so long as the audience can relate to it. In this sense, this interpretation gets invoked when it's believed that the story is much too personalized to the author and holds no real appeal to people besides them. Creeping cynicism over the ages has many hold that even stories that do work on a wide scale are both this and bad for it. Generally gets used in fanfiction when the story revolves around this character to the detriment of the canon it's taking place in.
Mary Sue as Infallible Character:
Related to the above, this is when the idea is that Mary Sue is a character that simply never fails. This, of course, is subjective beyond belief because there are almost no truly infallible characters. It's a logical paradox. Their very need for existence proves that they aren't infallible. This interpretation is a bit flawed in the sense that the absolute vast majority of protagonists out there are, to a degree, infallible. They have to be, lest their stories end in short order and most likely on an Anti Climax. People don't watch MacGyver just to see the title character get killed from an unexpected backfire of an improvised invention, with a "Game Over" and a cut to commercials for the remaining time.
The simple reality is that most people don't want to invest their emotional energy into failures. As such, it's almost universal in anything within a few degrees of the mainstream for the characters to ultimately find success in the end. The subjectivity of this interpretation relies on what is considered logical and acceptable, which varies a lot depending on genre, style, and the capabilities of the writers. There's no official line, so what people tend to do is think to themselves "what is the most I would accept?", go one over, and set their line there.
Mary Sue as Center of Attention:
Similar to the above, this posits that a Mary Sue is somebody that gets too much attention from the other characters, especially if their personality is something that should be driving them away. Even more blatantly subjective, this is pretty much impossible to measure and mostly comes down to "everybody should hate them because I hate them". It's worth mentioning that one of the goals of fiction is to provide the most interesting story possible within the "world" created (so to speak) and as a result, the most interesting characters to populate them. Most genres wouldn't work if the cast of most important characters wasn't limited.
Mary Sue as Alien Element:
A largely fanfiction interpretation, but it still rarely gets used in terms of actual shows. This viewpoint posits that Mary Sue is a character that involves changing the dynamic of a work and shifting the focus away from the established characters and styles. Often involves rewriting of canon elements and derailing of characters in the process. Very, very common in fanfiction that is written as an escape for the author rather than an appeal to a larger audience. In works with a shifting set of writers, this interpretation often gets used on characters that were introduced by a new writer that changes the work in an undesirable way. This interpretation often gets used on characters that were always part of a particular work's dynamic simply because of the implausibility surrounding them. Again, this is subjective.
Mary Sue as Fan Character Protagonist:
Similar to Alien Element, this interpretation extends to any and all Fan Character that takes a role of similar importance to a canon character regardless of their ultimate impact. Often gets applied even when it's perfectly logical that a new character would end up in such a role. Invoked by more cynical readers disillusioned about fanfic author's ability to create characters that fit the original source's setting and contain no traits related to author's personality and cultural upbringing.
Ruggedly handsome, charming, skilled, and respected by his peers. Think of a Captain Fantastic type. Kind of like The Ace, but not always played for comedy. Also often has a Dark And Troubled Past, but usually in such a light to emphasize their capabilities rather than their inherent specialness. Isn't nearly as common as Mary Sue as Character Type, but it certainly exists (some characters have been called "Marty Stu done right" before).
Not A Mary Sue
Of course, just as how a lot of attempts to classify what Mary Sue means, a whole set of definitions to nullify the Mary Sue label have come up. These are just as subjective as the above.
Likability/Real World Popularity:
The claim that likability nullifies any amount of Plot Bias, Character Derailment, implausibility, etc. Simple as that. Most people won't invoke just their personal feelings when using this, usually saying something along the lines of "well, millions of people do watch his antics every week". This interpretation is just as big a source of Flame Wars as its counter-part above. See also Quality By Popular Vote.
Flaws:
The other influential Not A Mary Sue argument, this claims that having a Fatal Flaw (or two... four... four hundred) makes them not ideal and, thus, not a Mary Sue. As mentioned in Mary Sue as Idealized Character, this usually results in other extremes that aren't too desirable.
Genre Exemption:
The claim that the very genre of the work is immune to accusations of Mary Sue. Generally comes up in genuine Escapist works such as Fairy Tales, Superhero comics, Romance Novels, Comedy (where it might simply be because they're a Mary Sue that makes it funny), and other such things.
Plausibility:
The claim that a character's Mary Sue status can be explained away by pointing out the plausibility of all the events. This kind of ignores the fact that most fiction is supposed to be about exceptional people.
Lampshade Hanging:
The claim that a Mary Sue is nullified if it is brought to the attention of the audience and turned into a meta-concept. The actual success of this may vary.