"to make fun of, to banter," 1845 (intransitive), 1852 (transitive), American English; according to "Dictionary of American Slang," the earliest example is capitalized, hence it is probably from the familiar version of the proper name Joshua. Perhaps it was taken as a typical name of an old farmer.
If those dates are correct, the word was in use earlier than the career of U.S. humorist Josh Billings, pseudonym of Henry Wheeler Shaw (1818-1885), who did not begin to write and lecture until 1860; but his popularity after 1869 may have influence that of the word, or even re-coined it, as it does not seem to have been much in print before 1875.
About the most originality that any writer can hope to achieve honestly is to steal with good judgment. ["Josh Billings"]
Related: Joshed; joshing.