The word which appears in Sanskrit ancient tomes is "Gāndhāra".
That refers to ancient Kingdom of Gandhara which is now part of North-West Pakistan. It's boundaries included Peshawar Region, Taxilla region and for some time, Swat region. It's people, as called by the Rigveda, were Gandhari People as mentioned in Rigveda 1.120.1, 1.126.7. It is backed up by archaeological finds of Gandhara civilization which are almost all found in North-West Pakistan, not Afghanistan.
Gandhara was conquered by Cyrus the Great and annexed into Persian Empire, just like modern-day Afghanistan was. Persians divided their eastern possessions into four satrapies. Kandahar was part of Arachosia Satrapy, while Gandhara was a Satrapy in its own right.
Then Alexander the Great took it from the Persians, Greeks further expanded the great civilization of ancient Gandhara onward, eventually adopting Buddhism and assimilating into local populace which is why Greek period is considered a distinct chapter of Gandharan art and civilization.
White Huns, considered to be forefathers of Modern Afghans (Excluding Hazara, Uzbeks and Tajiks), didn't appear in Afghanistan until much later. Not to mention, it was medieval Durrani dynasty which is considered the founder of Afghan state, thousands of years later.
You are not alone in making that connection however that Kandahar may have been named after Gandhara Kingdom of then North-West India, now North-West Pakistan. In Placenames of the World, author Adrian Room presents the same hypothesis. It seems wrong however. The Old city of Kandahar was founded by Alexander the great as Alexandria Arachosia hundreds of years after Gandhara had established and flourished. And the modern city of Kandahar was founded by first Durrani King Ahmed Shah. But the counter argument is strong as well, farming villages of Indus-Valley civilization existed just 17 miles away from Modern Kandahar. Same civilization can be considered mother of Gandhara.
Modern people of the regions included in Gandhara still proudly celebrate their heritage. There are two museums dedicated to Gandhara civilization in two cities of the former Kingdom of Gandhara. One is in Peshawar, Pakistan, the second one is in Taxilla, Pakistan. There is also a university named after the former-Kingdom in Peshawar, Gandhara University.
As for countries changing names, yes that happens. For example, your own country India was known as Aryavarta (Home of the Aryans), Bharat (After Emperor Bharat), Hindustan (Land of Hindus) and now Bharat again.
In conclusion, your assumption seems wrong because:
- Afghanistan is newer than Gandhara.
- Afghanistan was never known as Kandahar.
- Gandhara and Kandahar existed simultaneously under Persian, Greek and Maurya Empire.
- Afghanistan didn't exist as a national state before Durranis.
- There never was a Kingdom of Kandahar