I think this quote refers to 15th verse of Srimad Bhagavad Gita:
यं हि न व्यथयन्त्येते पुरुषं पुरुषर्षभ।
समदुःखसुखं धीरं सोऽमृतत्वाय कल्पते।।2.15।।
English Translation By Swami Gambirananda
2.15 O (Arjuna, who are) foremost among men, verily, the person whom these do not torment, the wise man to whom sorrow and happhiness are the same he is fit for Immortality.
The verse is saying that the person who doesn't get deviated with joy and grief of Samsara is eligible for Mukti. The control (संयम) of mind and indriya are essential for Yoga of which purpose is to concentrate and meditate upon Brahman. It's well known that Mind is the only cause of bondage and liberation (मन एव मनुष्याणां कारणं बन्धमोक्षयोः । - Maitrayini Upanishad 4.3.11).
In other words, here, the verse is talking about one's eligibility of attaining Moksha. We know that the only way to achieve Moksha is to know and realize Brahman. (नान्यः पन्था विद्यतेऽयनाय - Shukla Yajurveda 31.19). Now, Brahman can be attained by the practice/method of meditation (Shvetasvatara Upanishad 1.3) and for meditation (Dhyana Yoga), the control, stability and concentration of mind is essential.
Bhagavad Gita (English Translation By Swami Gambirananda):
8.9 He who meditates on the Omniscient, the Anceint, the Ruler, subtler than the subtle, the Ordainer of everything, of inconceivable form, effulgent like the sun, and beyond darkness-(he attains the supreme Person).
If mind get deviated upon the joy and grief of Samsara (which is due to attachment), s/he can't focus on the objective. Controlling mind is also believed to be very difficult (BG 6.34) however it can be controlled by practice and detachment:
6.35 The Blessed Lord said O mighty-armed one, undoubtedly the mind is untractable and restless. But, O son of Kunti, it is brought under control through practice and detachment.
👉 So, it's advised to get detached from feelings of joy and sorrow experienced in Samsara and take both (whether it's joy or grief) as same because the feelings of liking and hating distorts the mind:
7.27 O scion of the Bharata dynasty, O destroyer of foes, due to the delusion of duality arising from likes and dislikes, all creatures become bewildered at the time of their birth.
So, the quote you're reading is from the 2nd Adhyaya of Bhagavad-Gita, I recommend complete reading of Bhagavad-Gita. In the ending of second chapter, you'll get it more wisely:
2.56 That monk is called a man of steady wisdom when his mind is unperturbed in sorrow, he is free from longing for delights, and has gone beyond attachment, fear and anger.