We must realise that what we enjoy in this life is impermanent, and we must develop a detached attitude towards life, said M.V. Anantapadmanabhachariar.
There were kings who would retire to the forest and do penance, hence earning the title of Rajarishis. There were other kings who might not have retired to the forest, but carried out their duties while continuing to live in their kingdoms. But they were detached with regard to the power and pelf. Such a king was Janaka.
He carried out his duties as a king, but did so in the true spirit of a rishi, with no attachments whatsoever. He followed the path of karma yoga that the Lord was to talk about later in His Krishna avatara.
Kalidasa describes the detachment of Aja, the father of Raghu, with a simile that shows what true detachment is.
Aja decided to step down and made his son Raghu the king. One may well wonder if Aja, upon seeing the throne, would not feel sorry to have given up power. Kalidasa says Aja was so upright and detached that once he had decided that he would no longer be king, he saw the kingdom and the throne as he would his son's wife. Just as a man does not have base intentions with regard to his daughter-in-law, so too did Aja have no desires whatsoever with regard to his kingdom.
When Rama was about to leave for the forest, he picked up the garment made of bark that was laid out among the things intended for His now cancelled coronation. But what was a garment made of bark doing there in the first place? That garment was intended for Dasaratha, who had planned to retire to the forest after Rama's coronation.
However, one does not have to be a sanyasi to develop detachment. If one's lifespan is taken to be roughly hundred years, one must spend the first quarter studying.
The next stage is when one must earn a living. The third is when one must visit temples and spend time in the company of religious-minded people. If one has failed to do what one has to do in the first three stages of life, there is no point in thinking about the fourth.