Rebirth, karma-phala and avatarhood are the three main doctrines of Sanathana Dharma. Our Dharma Shastra mentions the cause of pain and suffering as the purposeful evil actions done in past lives. But the texts have given a more consoling type of interpretation for the sufferings of life, as they enable us to become more righteous in future and to reach the Lord, although there are so many unfortunate ones who do not realize this, even while suffering throughout their life.
Before thinking about suffering, we have to consider the criteria for committing the sins, from which the suffering comes. The four main criteria for performing evil deeds are: circumstantial influence, inherent tendencies born out of habit in past lives, unawareness of incurring suffering in future, and lack, of knowledge about Dharma Shastra.
In ancient India there were many great persons who underwent sufferings which enabled them to become more righteous and God-seeking. The Pandavas, Sudhama, Kunti Devi, etc., are examples of this. Kunti Devi even prayed to Lord Krishna to grant her pains and sufferings all the time so that she would remember Him continuously. Ranthi Devi prayed to the Lord to transfer all the sufferings of the world to him. Pain is a fundamental requirement even for the expression of ordinary love, let alone universal love.
It is said that great men also undergo great sufferings. Of course there are different reasons for why this is so. Yogis and mahatmas frequently take upon themselves the pains and sufferings of others. Christ, Ramakrishna, Ramana Maharshi, etc., are examples of this. Working against the ordained laws of nature also affects even great men. This itself is a law. Krishna, for example had to die by the arrow of a hunter, because Rama had killed Bali by false means in his last life. But great saints because of their dissociation from body consciousness and revelling in divine bliss do not experience the pain.
For ordinary persons the pain and suffering experienced in the sacrificial type of selfless service to the world is more desirable than merely undergoing suffering of a personal nature. Pain is the climax of humanism and the beginning of sacrifice. Prayers done for the welfare of oneself or for the world, with a heart full of pain, will be countless times more beneficial than the prayers done merely verbally without suffering. In fact, pain as well as suffering is a very good prayer to the Lord.