Enzymes are proteins, which means that they are composed of a long chain of amino acids that folds into a specific shape. This overall folding of the protein precisely positions the side chains of a few amino acids to form a so-called active site that can catalyze chemical reactions. A variety of intermolecular forces hold the protein in this shape. One important force is electrostatic interactions between positively and negatively charged amino acid residues.
pH becomes important in determining the shape that proteins adopt because at different pH values, certain amino acid side chains can become charged or uncharged. For example, the amino acid histidine has a positive charge at pH values below ~6 and a neutral charge at pH values above ~6. Since pH affects the charges of amino acids, it will affect the electrostatic forces that maintain an enzymes shape. At pH values far from the ideal pH of an enzyme, many important amino acid residues will have the wrong charge and therefore,the enzyme will not be able to fold into the right shape to function properly.
tl;dr: changing the pH of a solution can cause enzymes to misfold