The explosive device, planted near the entrance to the mosque, detonated when visitors were coming out of the building.
Since taking power in the country, the Taliban (under UN sanctions for terrorism) has been battling the local chapter of Daesh*, which is believed to be behind the majority of terrorist attacks and bomb explosions in Afghanistan. According to the Taliban, the Daesh* presence in the country is small and the movement has been working to eradicate the group.
*Daesh (IS/ISIS/ISIL) is a terrorist organisation banned in Russia.