यदाचरति कल्याणि शुभं वा यदि वाशुभम्।
तदेव लभते भद्रे कर्ता कर्मजमात्मनः॥
yad ācarati kalyāṇi śubhaṁ vā yadi vāśubham
tad eva labhate bhadre kartā karmajam ātmanaḥ
yat = that; ācarati = he engages in; kalyāṇi = O propitious; śubham = pious; vā = whether; yadi vā = or; aśubham = impious; tat = the; eva = certainly; labhate = attains; bhadre = and auspicious lady; kartā = the performer of an activity; karmajam = result of the activity; ātmanaḥ = for himself.
O propitious and auspicious lady, the performer of an activity certainly attains for himself the result of the activity that he engages in, whether pious or impious.1
1 Technical note: śubhaṁ aśubham vā yad ācarati tat ātmanaḥ karmajaṁ śubhāśubha-karma-janitaṁ sukhaṁ duḥkhaṁ vā kartā labhata eva.
1 Here is great insight from the commentator synthesizing his scriptural knowledge of the law of karma and the philosophy of ethics summarized as paropakāraḥ puṇyāya pāpāya para-pīḍanam: “Benefiting others is piety and harming others is sin.”
In order to describe his [former] sinful act that he had recollected now, he describes a feature of this world here.
He refers to Kausalyā as a propitious lady to console her.
In this world a man attains for himself the auspicious or inauspicious result that he brings about in others.1 The king implies here that because he had caused a sage to be separated from his son, the king is [now] separated from his [own] son.