When the soul dwells within Prakriti and gets attached to its gunas, it begins to experience them — pleasure, restlessness, dullness. And this very attachment — this clinging to the gunas — becomes the reason it takes birth in good or bad circumstances.
The principle is direct. Grab hold of a mango branch and you end up with mangoes. Grab the tamarind branch and you get tamarind. Whichever guna the soul clings to, that determines the nature of its next birth. This is the root mechanism of the cycle of rebirth.