This question doesn’t have a brief answer. Please click on the detailed answer.
Mizanul-Hikmah has narrated this hadith from the book Al-Gheybah of Nu’mani. Nu’mani narrates Ibrahim ibn Abdil-Hamid saying (regarding the Shias at the time of the emergence of the Mahdi (aj)): “One who had heard from Imam Sadiq (as) told me: “When the Qa’im (the standing/waiting one, Imam Mahdi (as)) emerges, one who used to think he was a follower of the imam (as) will disobey him and some like those who worship the sun and stars will accept the imam’s wilayah and authority [and join him].”
Although the narrators of this hadith are reliable, it is a mursalah hadith, because Ibrahim ibn Abdil-Hamid who is a companion of Imam Kadhim (as) says that ‘someone’ who had heard Imam Sadiq (as) told him, without specifying who the ‘someone’ is. Thus, this hadith is a mursalah one, making it unreliable.
As for the message of the hadith, it is saying that at the imam’s (as) time, some who thought they were true followers of the imam (as) will deny his leadership (as a result of not bearing the capacity for such) and authority. But on the other hand, a group of disbelievers whom the hadith refers to as “people like those who worship the sun and the stars” (meaning that they are mushriks) will grasp the truth and join the ranks of the imam (as) and aid him.
Therefore, this hadith is apparently speaking of those who claim to have faith and have accepted the authority and leadership of the imam (as), but when the time for action comes, they fail the test and disobey him; not only do they not reach salvation with the imam’s (as) emergence, but also join the wrong side and fight against him and end in total loss. Meanwhile, some who are on the wrong paths of shirk and kufr and fed up with all the oppression and injustice in the world will find faith in the imam (as) and accept his leadership when they see his just government.
Of course, Allamah Majlisi has narrated this same hadith with the same chain of narrators slightly different:
“When the Qa’em emerges, those who thought they were the followers of the imam will stray from this path and will become of those who worship the sun and moon (will become mushriks).”
Meaning that those who didn’t have true faith will not only desert the imam (as), but will turn away from Islam and join the ranks of the mushriks and enemies of Islam and the imam (as).
What this hadith is actually doing is point to the many hardships during the time of the imam’s (as) return, and that if one isn't ‘armed’ and ready with taqwa and piety and hasn’t taken refuge in true faith and good deeds, he well stray from the straight path.
 Nu’mani, Al-Gheybah, pg. 317; ReyShahri, Mizanul-Hikmah, vol. 1, pg. 187; “حدثنا أحمد بن محمد بن سعید ابن عقدة قال حدثنا حمید بن زیاد عن علی بن الصباح قال حدثنا أبو علی الحسن بن محمد الحضرمی قال حدثنی جعفر بن محمد عن إبراهیم بن عبد الحمید قال أخبرنی من سمع أبا عبد الله ع یقول:" إذا خرج القائم ع خرج من هذا الأمر من کان یرى أنه من أهله و دخل فیه شبه عبدة الشمس و القمر”
 Majlisi, Biharul-Anwar, vol. 52, pg. 364.