The Oxford English Dictionary states says that John Doe is "the name given to the fictitious lessee of the plaintiff, in the (now obsolete) mixed action of ejectment, the fictitious defendant being called Richard Roe.
An of the reasons why a fictitious tenant and a fictitious defendant were named is found in Charles Rembar's book The Law of the Land.
By extension from the law usage, John Doe is often used in computer software needing a default or example first and last name for a form.