Local government officials said the militants were killed while they were making an improvised explosive device (IED) to carry out a roadside bomb explosion.
Deputy provincial governor Mohammad Ali Ahmadi said the incident took place on Saturday morning in western party of Ghazni city.
Ahmadi further added that the Taliban commander was recognized as Mullah Sadiq who was killed along with four other militants following the explosion.
The Taliban militants frequently use improvised explosive device (IED) to target Afghan and coalition security forces.
This is not the first time that the anti-government armed militants are using mosque to prepare improvised explosive device (IED).
At least seven militants were killed while making improvised explosive devices (IEDs) inside a mosque in Deh Yak district late in March.