Śrīmad-Bhāgavatam · Text 9.18.32
Who is speaking and story frame
राजपुत्र्यार्थितोऽपत्ये धर्मं चावेक्ष्य धर्मवित् ।
स्मरञ्छुक्रवच: काले दिष्टमेवाभ्यपद्यत ॥ ३२ ॥
rāja-putryārthito ’patye
dharmaṁ cāvekṣya dharmavit
smarañ chukra-vacaḥ kāle
diṣṭam evābhyapadyata
When Princess Śarmiṣṭhā begged King Yayāti for a son, the King was certainly aware of the principles of religion, and therefore he agreed to fulfill her desire. Although he remembered the warning of Śukrācārya, he thought of this union as the desire of the Supreme, and thus he had sex with Śarmiṣṭhā.
Read Śrīla Prabhupāda's purport on Vedabase.io