In the pilot episode, McCoy got very angry at Spock and threated to break every bone in his body. Spock began calling him "Bones" to mock him. This made McCoy furious, so he grabbed a young crew member and dragged him off the bridge. Letter, when Spock returned to his room, the young man's bones were left piled on the bed. No one knew if the Doc ate the young man or just threw the rest of him away, but Kirk and company also began to call him Bones as a result, and the rest is history. Well, future history, I suppose...