Quotes from Oxford English Dictionary: 1. to tease. 2. to break the spirit of "She's a terror. I expect she'll try to take the mickey out of you all right!" (1948) ".... everyone was trying to take the mickey out of him" (1952 ff.)
The penis has nothing to do with the phrase, but 'mickey' is rare slang for a penis. James Joyce, in Selected Letters, 1909: "Gently undo ... the fly of my trousers and gently take out your lover's fat mickey."
A 'mickey' also is short for a Mickey Finn (knockout drops put in a sucker's drink). Supposedly from Finn's saloon (Chicago).