All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
A person is sociable by Fitrah (natural disposition upon which Allaah created mankind), so he likes to live amongst other people and socialize with them. Indeed, Islam came to confirm this Fitrah. The Prophet said: “The Muslim who mixes with people and endures their harm is better than the Muslim who does not mix with people nor endure their harm.” [Ahmad and At-Tirmithi]
Moreover, Abu Mas’ood narrated that the Prophet said: “A man from amongst the people before you was called to account (for his deeds) and it was not found that he ever did anything good, except that he used to mix with people and being well-off he used to order his servants to let off the man who is insolvent (from repaying his debt). He (the Prophet, sallallaahu ‘alayhi wa sallam) said that Allaah Said (to His angels): “We have more right than him to do this. Let him off.” [Muslim]
This is indeed the behavior of a strong believer who is better than a weak believer. Abu Hurayrah narrated that the Prophet said: “A strong believer is better and is more beloved to Allaah than a weak believer, and there is good in both.” [Muslim] Therefore, a Muslim should be keen on accompanying righteous people and he should cooperate with them in good, calling people to Allaah, enjoining good and forbidding evil. For more benefit, please refer to Fataawa 86353 and 86081.
The Ahaadeeth that are mentioned praising deserting people are regarding a particular period of time or a particular environment or about a specific person, like a person who doe not find any helper in doing good, and he feels weak in confronting the people by his own self, or that he fears that they will lead him to be tempted in his religion while he is unable to bear their harm, and so forth.
For instance, the Prophet said: “A time will come when the best property of a Muslim will be sheep which he will take on top of mountains and the places of rainfall (valleys) so as to flee with his religion from afflictions.” [Al-Bukhari]
Allaah Knows best.