First principle explanation of phase transition for Bose-Einstein condensates in optical lattices