When we pray due to suffering, we usually think that the suffering comes because of external situations and hence we have to pray.
But this is not correct. The very purpose of the suffering is that we should pray. By pouring our hearts out to the Almighty, we become closer to Him. Hence the suffering is a tool for our elevation.
Sources: Nachalas Yosef, Torah, p.125; Rabbi Zelig Pliskin’s Gateway to Happiness, p.255