Phase transitions are a many-body effects. You can not generate sharp transition with a finite number of degrees of freedom (or particles). However as you add particles the features of the system may become sharper. In the limit of infinitely many particles (thermodynamic limit) you get a truly discontinuous transition.
In practice nothing is infinite. The typical number of atoms in normal matter is however 10^(23) which is indistinguishable from infinity in the sense that phase transitions appear perfectly sharp.
The mechanism from which the transition occurs depends on the particular system and transition that you consider. For example, in the case of water freezing, you have a competition in between disorder (temperature) and atom-atom interaction. The atoms want to stick together in ordered pattern (crystal) but the temperature wants them to have random position. There is a critical temperature above which the disorder wins and below which it is the potential energy that is stronger.