Transpeptidase functions by catalyzing the formation of cross-links between amino acid residues in the peptidoglycan matrix of bacterial cell walls. This process involves the cleavage of D-Ala from the terminal end of the peptide chain and the formation of a new bond with a neighboring peptide. The resulting cross-links are essential for the rigidity and strength of the cell wall, preventing the bacterium from lysing due to osmotic pressure.