Size segregation in granular media induced by phase transition