In lysis buffer urea denature the protein and increase the solubility of protein.
MgCl2 is added to the lysis buffer since Mg2+ ions are co-factors for the enzyme used in the lysis buffer. This enzyme requires magnesium ions in order to function properly.
to disrupt cell membranes
Providing an osmotic shock to the cells
to inhibit divalent cation-dependent proteases