Where does the idea of "Episode 0" originate from? In the anime I've been watching lately, I see a lot of episode 0s popping up, which usually are published after the final episode and usually are not very comprehensible unless you have watched the series itself.

Where did this originate from and why do they do this?

Sample show:
Based on a google search for site:myanimelist.net "episode 0", we find the following episodes:


Candy Boy Episode 0 (a pilot, airing 6 months before Candy Boy)
Nichijou Episode 0 (a pilot, airing a month before Nichijou)
Haganai Episode 0 (a pilot, airing a few weeks before Haganai)
One Piece: Strong World Episode 0 (a prequel to One Piece: Strong World)
Koroshiya 1: Episode 0 (not sure about this one - Japanese Wikipedia says that it's about Ichi's past, so I guess it's a prequel?)
Hakuouki Hekketsuroku Episode 0 (a recap of the first season, and hence a sort of "prequel" to the second season, which aired a week later)
Ichigo Mashimaro Episode 0 (not sure about this one; it may be worth noting that it's called "Prologue" rather than "Episode 0" in Japanese)
UN-GO Episode 0 - Inga-ron (a prequel to UN-GO)
Also, Kyousougiga Episode 0 is a recap of the Kyousougiga ONAs, which are sort of pilot-y with respect to the Kyousougiga cour-length anime


There's a lot of prequels and pilots1 here. Prequel episodes typically occur chronologically before "episode 1" in terms of show timeline, while pilot episodes typically occur chronologically before "episode 1" in terms of the real world, and so it makes sense for either a pilot or a prequel to be numbered "episode 0". 



1 By "pilot", I mean any short piece that airs before a longer anime, whether or not it's a pilot in the US television sense, so this label includes teasers, animation test runs, etc.