Phase transition in a mean-field model for sympatric speciation