The men were handed over to the head of an Afghan reconciliation commission in the Afghan capital, Kabul.
Khan Zaman, a detainee, said: "Life was tough. They punished me." Zaman said he had been held for four years.
The men were among hundreds detained in Afghanistan on suspicion of being Taliban or al-Qaida members after US-led forces overthrew the Taliban government in late 2001.
Another man, Khodaidad, who also spent four years behind bars, said: "They didn't persecute me. I don't know why they held me, but I'm happy to be released from the custody of the infidels."
Sibghatullah Mojadeddi, the head of the government's reconciliation commission, gave each of the seven some money with which to get home.
Mojadeddi said the authorities were trying to bring other Afghans home from Guantanamo Bay.
The US military has released scores of prisoners from Guantanamo Bay but still holds about 500 at the prison at a US navy base in Cuba.
The US military is believed to be holding several hundred people at detention centres in Afghanistan.