Knock Sensor - 2000 Nissan Xterra

Just recently I had my head gasket replaced. Immediately upon driving away from the mechanic my Check Engine light came on. They assured me that it would go away after a few start and restarts but alas it did not. When I took it back in to the mechanic they told me that it was the Knock Sensor.

My question is, would replacing the head gasket do anything to cause the Knock Sensor to go off?

Correction
It was actually a head gasket cover. Also, there is not a continuous knock but there is a knock (just one) at random times when accelerating. It is not at a certain rpm nor is it consistent with anything else I am aware of. If the radio is on you would not be able to hear the knock, that is how quite it is when it does happen. Again, it is not a continuous knocking but one knock randomly.

That “knock” is pinging, which your knock sensor were it working would retard your ignition timing to prevent.

A “head gasket cover” is a head. Perhaps you mean valve cover gasket???

It would not be difficult to knock the wire off a knock sensor or even damage the wire when doing work around the heads. Th shop should have test drivien the car and picked up and corrected the problem before returning the car to you as repaired, however on an eight year old car it truely could be a coincidence.