In many epic stories, sages always do yajnas. What is the reason behind it? I am assuming there might be a universal reason such as "for the good of the realm".
But does someone know the exact reason?
Hinduism Stack Exchange is a question and answer site for followers of the Hindu religion and those interested in learning more about Hinduism. It only takes a minute to sign up.Sign up to join this community
Yajna can be of many different types. The fourth chapter of Bhagavad Gita lists many of them. But the ones you are referring to are commonly known as fire sacrifices. While yajna generally is the activity of fire sacrifice, the purpose and reason behind doing it can be different.
The primary purpose of yajna is to offer oblations to the gods. Now, the reason why some one would try to please the gods can be different. A person may do so for fulfilling his material desire or for some other purposes. But the sages in the ancient times used to do so for the welfare and prosperity of the human beings:
saha-yajñāḥ prajāḥ sṛṣṭvā purovāca prajāpatiḥ
anena prasaviṣyadhvam eṣa vo ’stv iṣṭa-kāma-dhuk [BG - 3.10]
In the beginning of creation, the Lord of all creatures sent forth generations of men and demigods, along with sacriﬁces for Viṣṇu, and blessed them by saying, “Be thou happy by this yajña [sacriﬁce] because its performance will bestow upon you everything desirable for living happily and achieving liberation.”
As gods are simply higher beings existing in the material world, they too need nourishment and power for their prosperity. By performing yajnas we can benefit them and in return they'll benefit us through rain, fulfilling desire, etc. Hence, performance of yajna for the gods has been suggested in the Gita as through mutual cooperation we both will prosper:
devān bhāvayatānena te devā bhāvayantu vaḥ
parasparaṁ bhāvayantaḥ śreyaḥ param avāpsyatha [BG - 3.11]
The demigods, being pleased by sacriﬁces, will also please you, and thus, by cooperation between men and demigods, prosperity will reign for all.
So sages used to do yanja for the benefit of the gods which in turn would benefit the human beings.