It is narrated from Sayyiduna Abdullah bin Abbas, may Allah be pleased with them both, that the Messenger of Allah, peace and blessings be upon him, came to his companions while they were sitting. He, peace and blessings be upon him, said: Shall I tell you who is the best man in terms of rank? They said: Yes, indeed, O Messenger of Allah! He, peace and blessings be upon him, said: He is the man who holds the reins of his horse in the way of Allah, until he dies or is killed. Shall I tell you about the person whose rank is after him? They said: Yes, O Messenger of Allah! He, peace and blessings be upon him, said: He is the man who, secluded in a mountain pass, establishes prayer and pays zakat, and keeps away from the evils of people. Now, shall I tell you whose rank is the worst? They said: Yes, O Messenger of Allah! He, peace and blessings be upon him, said: He is the man who is asked in the name of Allah, but still does not give.
Hadith Referenceالفتح الربانی / كتاب الجهاد / 4813
Benefits: … To remain secluded in a valley, to adopt isolation in normal circumstances, and to separate oneself from the Muslim society is not permissible. Congregational prayer (salah in jama‘ah) and Friday prayer (jumu‘ah) are obligatory. Visiting the sick and helping the weak are also among the rights of Muslims; all of this is only possible within society. A solitary person would be neglectful of all these obligations and rights—how then could he be considered superior? However, if by living in society there is a strong likelihood and danger of the religion being lost, then seclusion is better; but it is not permissible merely on the basis of imagined dangers. Observe that the noble Companions (radi Allahu anhum), despite enduring extreme hardships, did not abandon society; rather, they continued striving for its reform. Furthermore, propagation (tabligh) is also an obligation, and this too is only possible by living within society.