It is suspected that the killing was a fallout of gang war, a police officer said.
Superintendent of Police (Rural) Lallan Mohan Prasad said that rival gang members opened fire at notorious criminal Guddu Singh while he was coming out of the court after production.
Two other undertrial prisoners were injured in the firing, the SP said, adding they were out of danger.
Guddu Singh was a history-sheeter and he was facing over 25 criminal cases, the SP said.