Presumably you mean when the expression is used to accuse someone of making a false comparison. I think it simply comes from the facts that a) apples and oranges are often used in elementary arithmetical questions about numbers, weights, prices etc. and b) because they have certain similarities (they're both round fruit) but are also very different (in colour, texture and taste).