The gemoro Nedarim 40 explains how important it is that anyone who visits the sick should pray for the sick person while visiting.
Any sort of suffering, including illness, can be brought about by having sinned, see here . The sin can be a barrier to recovery but repentance can remove the barrier.
This article by the Chicago Community Kollel points out the importance of the righteous person in praying for a sick person and says:
The Shulchan Aruch states that one who has a choleh in his house
should consult with a talmid chacham (Torah sage) to daven (pray) for him (Y. D. 335-10).
How do we understand this concept and what is the actual role of the
tzaddik (righteous person) when he is consulted? The Meiri writes (Taanis 8A) that the
real purpose of visiting a tzaddik is in order for the tzaddik to
advise him on the proper course of teshuva (repentance) and tefilla
The Sefer Chasidim (755) writes that the tzaddik should investigate
the petitioners’ ways to see if perhaps there is a particular sin
which may be the cause of this persons’ troubles. The tzaddik should
then tell the person, “If you want me to daven for you, you must fix
yourself in this particular area”.
So we see that