Two years after surgery for carple tunnel, my scar is swelling and it hurts if pressed. Any ideas on what might be wrong?

Carpal tunnel . Have you had any steroid injection done? That would be an option first.
Scar pain. Painful scars after carpal tunnel releases is unusual after several months. At two years i worry that a sensory nerve or the median nerve is caught in the scar or you have a painful keloid. You need a second opinion from a hand surgeon.
Have it examined. If it has been like this since the operation, it may be a hypertrophic scar or keloid. If the scar was better and has now become more prominent and tender, that is very unusual. Either way, you should return to the surgeon who did the operation for an examination.