Patanjali Yoga Sutra — संस्कारसाक्षात्करणात् पूर्वजातिज्ञानम् ॥3.18॥
Saṃskārasākṣātkaraṇāt pūrvajātijñānam॥
Through the performance of saṃyama on subtler impressions of thoughts and actions, a yogi can get mystical power to know past lives.
We have understood that saṃskāra is nothing but sum total of all impressions of our thoughts and actions (of not only present life but of the previous lives also). In this chain of different lives, these impressions are recorded in sūkṣma śarīra of jīva in the form of memory, retrievable at any time. But to retrieve, one should have occult power, thus capable of reading these impressions. That means the link between different lives is the saṁskāra. By understanding these saṁskāras, through saṃyama, the yogi gets the perfect purity of his mind and will have this power of knowing past lives (his as well as others).
But as said earlier, any power acquired could be a hurdle in one’s sādhana. Here is an anecdote from Rāmānayaṇa. There was a great sage and he had acquired various siddhis (powers) through his austerities (Tapas). Indra saw this and felt, ‘The sage is acquiring a lot of energy through his tapas and one fine day, he might dethrone me from my Devendra seat (Kingship of Gods). Somehow, I should stop him’. He approaches the sage and hands over a sword and requests — ‘Oh sage, please take care of this sword. Sometime later, I would take it back from you’. The sage accepts and starts taking care of the sword. He was carrying it wherever he was going. Slowly, his cruelty increased and started using the sword against some animals, either to threaten or to kill them. Gradually, his sādhana completely stopped and was destroyed. The powers are like this unwanted and misleading sword!