HNPCC is primarily caused by mutations in one of several genes responsible for DNA mismatch repair, including MLH1, MSH2, MSH6, PMS2, and EPCAM. These genes usually correct errors that occur during DNA replication. When these genes are mutated, the errors accumulate, leading to increased cancer risk.