An unidentified or anonymous person
"Any mere imaginary persons, or men of straw. John Doe, Richard Roe, John o'Noakes, and Tom Styles are the four sons of "Mrs. Harris", all bound apprentices to the legal profession."
- Brewer's Dictionary of Phrase and Fable
We see it on the television, we read it in the newpaper and hear it on the radio. "Unidentified man dies in bizarre train accident". As a society, we hate a mystery of this sort. We need names. Our family and friends have names, and it's inconvenient to call them by anything else. So equally, for those anonymous folk, we adopt a custom which dates back hundreds of years, at least to the time of Edward III, and we give them a name.
A legal John Doe
In the fourteenth century there were many debates over title to land, and many legal cases wrangled. In one of these, over the Acts of Evictment, a hypothetical person leased land to another man, who subsequently evicted him from his own land. To enable satisfactory discussion, the two were allotted names. The landowner was John Doe, the lessee became known as Richard Roe. Whilst the names meant nothing of themselves, both "doe" and "roe" had reference to deer, possibly indicating the origins of the legal argument (i.e. who was allowed to hunt on the debatable land).
Some sources state that it dates back to 1215, the Magna Carta, which required that two witnesses be named in every legal action. There were apparently occasions where two witnesses were not available, hence Messrs. Doe and Roe would be used.¹
In legal terms, John Doe is "a party to legal proceedings (as a suspect) whose true name is unknown or withheld", presumably for protection. The female equivalent (Jane Doe or Mary Roe), is also used in this setting.
Joe Bloggs, and Co.
So where does that leave us? The legal tradition having been set, it became practice for any unidentified person or body to become known by one of these anonymous names. so someone turning up in a hospital or a police station who is dead on arrival, unconscious or suffering from memory loss becomes John Doe. It's easier to think of them as people once they have names.
The name is also used in a similar way to John Q. Public (or in England "Joe Bloggs"), to refer to "Everyman". Of course, all of this leaves the real John Does and Mary Roes of this world in a pickle. As with anyone who has the same name as a popular figure, they may be the subject of teasing. But at least they know they aren't truly anonymous.
¹ Unable to confirm this - even Encyclopædia Britannica let me down