The primary cause of change in the composition of a magma is cooling, which is an inevitable consequence of the magma being formed and migrating from the site of partial melting into an area of lower stress - generally a cooler volume of the crust.
Cooling causes the magma to begin to crystallize minerals from the melt or liquid portion of the magma. Most magmas are a mixture of liquid rock (melt) and crystalline minerals (phenocrysts).
Contamination is another cause of magma differentiation. Contamination can be caused by assimilation of wall rocks, mixing of two or more magmas or even by replenishment of the magma chamber with fresh, hot magma.
The whole gamut of mechanisms for differentiation has been referred to as the FARM process, which stands for fractional crystallization, assimilation, replenishment and magma mixing.