every enzyme requires some conditions in means of pH, ionic strength, present cofactors etc. That you get by adding the buffer to the reaction mixture. In some cases, the enzyme may even shift pH in non-buffered solution and thus it would stop working, but adding buffer prevents that also.
So, by adding the buffer to PCR reaction you get the optimal pH and Mg2+ is required as cofactor as by most NTP-binding proteins (look into some book for properties of DNA Pol)
Hola, It´s to be sure that the enzyme works in the best conditions. For instance the taq , Pfu polimerases had an optimun pH about 8 and required an specific Mg conc. if you made your pcr at pH 6 without Mg the result could be no amplification because the residual activity of enzyme would be innefficient tp amplify the wished band. Buena suerte