In this week's Parsha, the Posuk states, "לא יסור שבט מיהודה ומחקק מבין רגליו," teaching that the seat of royal power shall not be removed from the tribe of Yehudah (בראשית מ"ט:י'). The Ramban says that based on this Posuk, we can understand why the Chashmonaim, who ruled during the second Beis HaMikdash period, were punished. The Chashmonaim, who were Kohanim, were descendants of the tribe of Levi and for this reason were not permitted to occupy the throne. Consequently, four consecutive kings from their family fell into the hands of the enemy and had tremendous difficulty in general. Substantiating this idea, the Gemara presents primarily negative comments about the Chashmonaim despite their heroism associated with Chanukah.
When one reads the Rambam's description of the Chanukah story, however, one finds that he merely tells the story, praises the accomplishments of the Chashmonaim, and fails to even offer one word of criticism of them (פרק ג' מהל' חנוכה הלכה א'). Why is this so? Harav Joseph B. Soloveitchik suggests that perhaps one can understand the Rambam in light of the well known Halacha of עת לעשות לה' הפירו תורתיך, meaning that when it is necessary at a certain time to preserve Hashem's Torah, one can temporarily abandon one of its Mitzvos. For example, the Halacha states that the Torah Sheb'al Peh may not be written, yet based on this Halacha of עת לעשות לה', a decision was reached to record in writing all of the Talmud to preserve the body of Torah Sheb'al Peh which otherwise would have been forgotten.
Similarly, the danger presented by the Yevanim focused on the Beis HaMikdash. Their attempt to eliminate the Avodah of the Beis HaMikdash was designed to undermine all of Judaism. The Chashmonaim, as Kohanim, had the task to guard the sanctity of the Beis HaMikdash. They therefore felt compelled to assume political control in order to effectively combat the forces of the Yevanim. Based on the Halacha of עת לעשות לה', the Rambam decided that the behavior of the Chashmonaim, though against our Posuk, was appropriate nonetheless.