When and how the atmas were created? Which sacred text explain it?
Atmas (souls) were never created. Atma is eternal, ever existing and unborn:
na jāyate mriyate vā kadācin nāyaṁ bhūtvā bhavitā vā na bhūyaḥ
ajo nityaḥ śāśvato ’yaṁ purāṇo na hanyate hanyamāne śarīre [BG - 2.20]
For the soul there is neither birth nor death at any time. He has not come into being, does not come into being, and will not come into being. He is unborn, eternal, ever-existing and primeval. He is not slain when the body is slain.
Jiva being part of God, is also eternal and ever existing like God:
mamaivāṁśo jīva-loke jīva-bhūtaḥ sanātanaḥ [BG - 15.7]
- The living entities in this conditioned world are My eternal fragmental parts.
tava puruṣaṁ vadanty akhila-śakti-dhṛto ’ṁśa-kṛtam [SB - 10.87.20]
- Vedas say that the soul is a manifested part of Your as you are the possessor of all energies.
Creation and annihilation are going on eternally cyclically. At the time of annihilation, jivas enter into God and again manifested back (not created) upon next creation as they were:
sarva-bhutani kaunteya prakritim yanti mamikam
kalpa-kshaye punas tani kalpadau visrijamy aham [BG - 9.7]
O son of Kunti, at the end of the millennium all material manifestations enter into My nature, and at the beginning of another millennium, by My potency, I create them again. That is, the material world manifests again and the jivas resume their activity.
Just like heat and light are the integral part of fire, so are the jivas are integral part of God, maya being the other. So the Vishnu Puran mentions the energies as below:
viṣṇuśaktiḥ parā proktā kṣetrajñākhyā tathāparā
avidyā karmmasaṃjñānyā tṛtīyā śaktiriṣyate [VP - 6.7.61]
Vishnu shakti is called as superior and khetranja (jiva shakti [BG - 13.2]) is called inferior and the third energy named karma is known as ignorance (maya).
This also has been mentioned in Chaitanya Charitamruta:
kṛṣṇera ananta-śakti, tāte tina — pradhāna
‘cic-chakti’, ‘māyā-śakti’, ‘jīva-śakti’-nāma [CC - 2.8.151]
Krishna has infinite energies among which three are primary. Their names are: chid shakti (same as Vishnu shakti in the above verse), maya shakti and jiva shakti.
So the point is, the jiva being an energy potency of the Lord, is also eternal like Him. So no body created the atmas, they are eternal and unborn.