The author (may Allah shower blessings on him) stated in the book, Riyaad us-Saaliheen: The Chapter of Desirability of Seclusion at times of Corruption Committed by the People of the World, and what is similar to that.
You must know that the best person is a believer that lives with the people and exercises patience on their harm. He is better than a believer who does not live with them and does not patiently bear their harm. Nevertheless, there are instances when it will be more desirable for one to withdraw himself from people than to mix with them. If a person fears tribulation for himself; for instance, if one is in a country where the government wants the people to forsake their religion, or wants the people to support an innovation (in the Deen). In addition, if he is in a place where sin is the order of the day or where he fears falling into prohibitions and similar instances, then seclusion may be the best option.
Hence, one must leave a Land of Disbelief for a Land of Islam, and migrates from a land of evil to a righteous country.
Another reason for moving into seclusion is a negative change in the condition of the people. Thus, it has been authentically reported from the Prophet ﷺ that: 'Perhaps the best possession of a Muslim will be a herd of sheep with which he retires to the top of a mountain or places where rain is expected to fall, so as to safeguard his faith from tribulation'.
So this is the distinction; seclusion becomes desirable if there is evil and tribulation in mixing with people. Otherwise, the basic principle is that mixing with people is better. In doing this, he can command them to do good and forbid them from evil, he can call them to the truth and explain the Sunnah to them. This is best.
However, if he cannot extend his forbearance in the face of tribulation, then that he isolates himself from people is better even it implies moving his worship to mountaintop or valleys.
Then the Prophet ﷺ explained the excellence of a person whom Allah – the Mighty and Sublime - loves, he ﷺ said: 'Allah loves a slave who is pious, free of all wants and the unnoticed'.
'At-Taqiyy' – the one that fears Allah – the Mighty and Sublime
- such that he carries out Allah's orders and turns away from His prohibitions. He carries out His commandments such as observing the Prayer in congregation, disbursing the Zakat to those entitled to it, observing the fast of Ramadan, going on Hajj, being dutiful to parents, joining ties of kinship, doing good to the orphans and all other forms of good deeds.
'Al-Ghaniyy' – the one that makes himself independent of people, he is contented with what Allah– the Mighty and Sublime - has given him. He will not ask from people nor show himself to them as downtrodden; rather, he is free from people, he knows himself, he is satisfied with his Lord– the Mighty and Sublime, and he will not turn to anyone.
'Al-Khafiyy' – the one that does not make himself known; he is not bothered about people, even his children, knowing him or talking about him. You will always see him moving between his house and the mosque, the houses of his brothers and relatives unnoticed; he conceals himself.
Nonetheless, this does not mean a person should remain in his house without teaching anyone if Allah– the Mighty and Sublime – has granted him knowledge. Such person is only feigning piety. It is better for him to teach people than sit in his house without people benefitting from his knowledge or sit at home without people benefitting from his wealth.
However, if the matter is between the urge to make himself known and noticed and the urge to hide himself, then he should conceal himself. Then, if there is no way for him but to make himself known, let him make himself acknowledged; this is among whom Allah– the Mighty and Sublime - loves.
There is an encouragement for one to conceal himself, make himself independent of people but from Allah– the Mighty and Sublime, fear his Lord– the Mighty and Sublime - so that he can worship Him– the Mighty and Sublime - in harmony and goodness.