At the time of death, according to the thinking, feeling and willing of the mind, which is involved in fruitive activities, one receives a particular body. In other words, the body develops according to the activities of the mind. Changes of body are due to the flickering of the mind, for otherwise the soul could remain in its original, spiritual body.
Srimad Bhagavata Purana
श्रीमद्भागवतमहापुराणम्
मूल श्लोकः
यतो यतो धावति दैवचोदितं मनो विकारात्मकमाप पञ्चसु । गुणेषु मायारचितेषु देह्यसौ प्रपद्यमानः सह तेन जायते
yato yato dhāvati daivacoditaṃ mano vikārātmakamāpa pañcasu | guṇeṣu māyāraciteṣu dehyasau prapadyamānaḥ saha tena jāyate
SB 10.1.42