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, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
The Prophetic narration which you mentioned in the question is authentic and was reported by Ahmad, Abu Daawood, Ibn Maajah, An-Nasaai and others . Its meaning is that a time would come where the pious and righteous people would be rare and the debased would prevail and would betray their covenants and not fulfil their trusts. The debauched would be so many and mix with other people in a way that the faithful would not be distinguished from the unfaithful, and the pious would not be distinguished from the dissolute people. It is at this time that a Muslim should accept what he believes to be the truth and act upon it, and abandon what he believes to be falsehood, he should attend to his own affairs and protect his faith and abandon people and not follow them.
Some interpreters of this narration said that this is permission for abandoning enjoining good and forbidding evil when the evil doers would be so many and the righteous would be weak and small in number.
However, this does not mean that the pious should abandon enjoining good and forbidding evil even when they are able to change the evil, because this Prophetic narration should be understood within the context of other narrations which prove the obligation of enjoining good and forbidding evil. Therefore, this narration should be applied to when enjoining good and forbidding evil is absolutely of no avail, or when it is feared to cause greater harm; in which case one should change the evil in his heart (i.e. detest it), and the pious should seclude themselves and not mix with the people. However, if enjoining good and forbidding evil is effective in the society, then the original ruling of it being obligatory remains.
Allaah Knows best.