Why do pilots have the ability to turn off the transponder in-flight?
Basically everything that consumes power on an aircraft can potentially cause interference, short-circuits, or otherwise jeopardize the safety of flight and therefore must be switchable. Sometimes the switch is in the form a button, otherwise by a fuse. 

There are several particular reasons that the transponder can be turned off.

If the transponder malfunctions, it may cause interruptions to all ATC surveillance in an area. There have been occurrences in the past that due to a fault the transponder it was basically acting as a radar jammer. 

In one particular incident it took a while before the aircraft that caused it was identified and after requesting the pilot to switch of the transponder, secondary surveillance was restored. 

Another reason is that when the aircraft is at the gate, the transponder is switched of to reduce the amount of radio transmissions. 100 aircraft on the surface of a large airport can produce a massive Radio Frequency noise, which negatively affect radar systems. When taxiing, radar replies are useful for aircraft identification, hence the transponder is switched on at push-back or engine start. 



For an example to see how such requirements are worded in aircraft certification regulations, see rbp's answer.



The focus here and in the media1 on the transponder in relation to hijacks is a red herring. If an aircraft is hijacked, there are way more important things to worry about than an active radar transponder.
If hijackers turn off the transponder it means that they have access to the cockpit already. 

1This answer was written shortly after flight MH370 went missing while en-route from Kuala Lumpur to Beijing. Initial speculation focussed on a possible hijack scenario.