In order to study analytically the nature of the size segregation in granular mixtures, we introduce a mean field theory in the framework of a statistical mechanics approach, based on Edwards' original ideas. For simplicity we apply the theory to a lattice model for hard sphere binary mixture under gravity, and we find a new purely thermodynamic mechanism which gives rise to the size segregation phenomenon. By varying the number of small grains and the mass ratio, we find a crossover from Brasil nut to reverse Brasil nut effect, which becomes a true phase transition when the number of small grains is larger then a critical value. We suggest that this transition is induced by the effective attraction between large grains due to the presence of small ones (depletion force). Finally the theoretical results are confirmed by numerical simulations of the 3d system under taps.PACS numbers: 45.70. Mg, 64.75.+g, 05.50.+q In the last decades a great attention has been devoted to the study of the problem of vertically shaken granular mixtures under gravity. It was observed that such systems depending on the control parameters can mix or segregate their components spontaneously according to a mechanism which is still largely unclear, although of deep practical and conceptual relevance [1,2]. Rosato et al. [3] showed that large grains surrounded by a sea of smaller ones rise to the top when subjected to vertical shaking. This is the well known "Brazil Nut Effect" (BNE), while the opposite one (i.e. large grains on the bottom and small ones on the top) is known as "Reverse Brazil Nut Effect" (RBNE) [4,5]. The BNE was originally explained [3] in terms of a geometric effect, based on "percolation" arguments. Along with geometry, dynamical effects, such as convection [6] or inertia [7], were shown to play a crucial role. The hydrodynamic equations for binary mixtures [8] were also applied, and in this framework the regimes of BNE and RBNE [9] were found to depend on the presence of inelastic dissipation.Recent results finally outlined that segregation processes may involve global mechanisms, such as condensation [4] or phase separation [10]. This suggested a change of perspective on the issue and the idea to formulate a statistical mechanics description of these phenomena [4,11,12]. To this aim, in Ref.s [4,11] the interplay between size and mass was studied and a phase diagram for BNE/RBNE transition based on the competition between percolation and condensation was proposed.In the present paper, applying a statistical mechanics approach for non-thermal systems [13,14], a new purely thermodynamic mechanism is found responsible for size segregation. We follow a statistical mechanics approach for granular materials under taps, which was recently developed [15] on the basis of Edwards' original ideas [13,14]. This approach postulates that time averages coincide with suitable ensemble averages over the mechanically stable states (i.e. those where the system is found at rest). Such hypothesis was shown [15] to hold with good appro...