And do I want one?
The earliest use of the term headcanon was 2007, but it became popular in 2010. Fanlore defines a headcanon as "a fan's personal, idiosyncratic interpretation of canon, such as the backstory of a character, or the nature of relationships between characters."
"Canon" is considered the "text" of a book, movie, or tv series. So in Pride and Prejudice Elizabeth and Darcy end up together: that's what happens in the book, so it's canon. But the book ends before we see their wedding. If you think that Elizabeth would be a total Bridezilla, that's your personal headcanon. The book doesn't demonstrate this, but you're entitled to what you imagine about the characters.
Who shot first: Han or Greedo?
Sometimes headcanons arise because of inconsistencies in storytelling (the Star Wars re-release caused confusion among fan communities, because the new Cantina Scene appeared to be different from the original). Some headcanons reimagine characters as LGBT, because fans feel that kind of diversity is too scarce. Often, fans do this without realizing: they make assumptions about the characters or circumstances that, while based on the canon, are not actually textual interpretations.
Headcanon vs. Canon vs. Fanon
So we know that a headcanon is an individual experience, an idea or conviction you might have about a piece of media. This can include or be inspired by subtext, or it can be a completely separate conclusion drawn from personal opinions or desires.
Canon is literally what the original media says or purports to be. While one could argue that sometimes subtext is intentional and part of canon, overall canon is understood to be speculation-free. It's literally what happened on screen.
So what the heck is fanon?
Fanon is a communal headcanon, that a group or groups of fans have accepted, either intentionally or through osmosis. A popular headcanon among the Sherlock community is that John Watson always makes the tea. This is actually so well-recognized that fans often either forget or don't know that this is entirely false: in the show, the only character seen making tea is Sherlock (though Mrs. Hudson is often providing it, she never makes it on screen).
[Text: i head canon human fluttershy as an Indian or Pjilippina trans girl who is lesbian. i also head canon rainbow dash as a mixed black-latina demi-girl who identifies as lesbian. they're totally dating. :D]
Why is this a thing?
Fans have had headcanons since there was media to enjoy. I'm talking ancient Greek disagreements over whether Patroclus and Achilles were lovers, and if so: who bottomed? (Yeah, those arguments are as old as time). Because being a fan is such a personal experience, our minds tend to get very focused on the media we love. Headcanons are often a creative outlet for us; they allow us to continue enjoying the story even though we're not currently experiencing it.
Here are a few of my favorite headcanons, organized by fandom:
Harry is going to be really great dad, the kind with pockets full of chocolate Draco Malfoy gets REALLY into Muggle stuff after the war Hermione Granger keeps her maiden name when she gets married
Bruce Banner is an environmental activist Sam Wilson is a total foodie Tony Stark funds nonprofits for women in STEM
Irene Adler still texts Sherlock, he just remembers to put his phone on silent now Anthea is actually the one running the government Sherlock still sneaks cigarettes
Fans share their headcanons through blogs, fanfiction, and art. They use headcanons to make fan spaces more diverse and welcoming, to build community, and to keep creating content even though the original media has been cancelled or is on hiatus. Obviously, some fans keep their headcanons to themselves (you probably have some of your own that you might not have realized until now). Headcanons aren't all that strange- the term may be new, but the phenomenon is centuries old. They're a way of experiencing media.