The group "perpetrated grave crimes against civilians and public security", the presidential palace said.
President Ghani has pledged a tougher response to the Taliban after an attack in Kabul last month left 64 dead.
Meanwhile Taliban fighters have attacked police checkpoints on the outskirts of Lashkar Gah, the main city in Helmand province.
The assaults bring to an end a lull in fighting during the annual opium harvest in Helmand, a Taliban stronghold.
The Taliban said it overran two checkpoints, killing 15 security officers. But police said 14 fighters were killed before the group was driven off.
Opium provides the Taliban with one of its main sources of income and last week a US general warned a bumper crop this year could fuel attacks.
Two of those executed were involved in the killing of former President Burhanuddin Rabbani in 2011, Afghan television reported.
All of those hanged were tried and convicted in accordance with the law, the presidency said.
After the attack in Kabul last month, one of the worst in Afghanistan  for years, President Ghani promised to "show no mercy" punishing the Taliban, vowing to enforce legal punishments including executions.
Peace efforts stalled this year after the Taliban refused to participate in new talks with the Afghan government until foreign forces left the country.
The militants have been waging an insurgency against the Afghan government since being ousted in 2001.
Nato ended its combat mission in Afghanistan in December 2014, leaving a 13,000-strong residual force used for training and counter-terrorism operations, including 9,800 US troops.
Afghanistan has hanged six Taliban inmates in the first executions since Ashraf Ghani became president in 2014.