Abdul Rahman Mangal said Faiz ul Rahman Wardak, a fourth-year student at Kabul Polytechnic University, was hanged in Sewaka village in Chak district, 60 km (37 miles) outside the Afghan capital.
He said local Taliban insurgents accused him of being involved in the assassination of a Taliban intelligence official named Mullah Mirwais.
"He wanted to spend his holiday at home but was captured on Thursday by local Taliban and they hanged him in public," Mangal said. "As soon as we got information, we tried to help him but the Taliban hanged him immediately."
Photographs apparently showing the body of the man, hanged by the neck from an improvised gallows, circulated on social media.