The Rambam provides the following background as an introduction to his laws of Chanukah:
בבית שני כשמלכו יון גזרו גזירות על ישראל ובטלו דתם ולא הניחו אותם לעסוק בתורה ובמצוות. ופשטו ידם בממונם ובבנותיהם ונכנסו להיכל ופרצו בו פרצות וטמאו הטהרות. וצר להם לישראל מאד מפניהם ולחצום לחץ גדול עד שריחם עליהם אלקי אבותינו והושיעם מידם והצילם וגברו בני חשמונאי הכהנים הגדולים והרגום והושיעו ישראל מידם והעמידו מלך מן הכהנים וחזרה מלכות לישראל יתר על מאתיים שנה עד החורבן השני. וכשגברו ישראל על אויביהם ואבדום בחמישה ועשרים בחודש כסלו היה ונכנסו להיכל ולא מצאו שמן טהור במקדש אלא פך אחד ולא היה בו להדליק אלא יום אחד בלבד והדליקו ממנו נרות המערכה שמונה ימים עד שכתשו זיתים והוציאו שמן טהור. ומפני זה התקינו חכמים שבאותו הדור שיהיו שמונת הימים האלו שתחלתן מליל חמשה ועשרים בכסלו ימי שמחה והלל ומדליקין בהן הנרות בערב על פתחי הבתים בכל לילה ולילה משמונת הלילות להראות ולגלות הנס. וימים אלו הן הנקראין חנוכה והן אסורין בהספד ותענית כימי הפורים. והדלקת הנרות בהן מצוה מדברי סופרים כקריאת המגילה.
In the time of the second Beis HaMikdash, the Greeks conquered Eretz Yisrael, passing harsh decrees against the Jews, restricting their religion, and forbidding them from practicing Torah and mitzvos. The Greeks stretched their hands out to seize our property and our daughters. They forced their way into the Beis HaMikdash, smashed its walls, and defiled its purity. They caused the Jews great distress and anguish, until finally the G‑d of our forefathers had mercy on us and rescued us from their hands.
Then, the Sons of the House of Chasmonaei, the Kohanim Gedolim, overpowered them and defeated their forces. They rescued Bnei Yisrael from the hands of the Greeks, and appointed a king from among the Kohanim. Then began a period of Jewish autonomy which lasted more than two hundred years, until the destruction of the second Beis HaMikdash.
Bnei Yisrael defeated their enemies on the 25th of Kislev. They then entered the Beis HaMikdash and found one last vessel of pure oil, which was enough to last for only one night. Nonetheless, they lit from it the candles of the Menorah for eight nights, until they were able to press new olives and produce a new batch of pure oil.
For this reason, the Sages of that generation decreed that the eight days beginning from the 25th of Kislev would be days of joy and hallel, in which candles would be lit at night beside the entrances of Jewish homes, to proclaim and publicize the miracle. These days are called “Chanukah,” in which it is forbidden to eulogize or fast, similar to Purim. Lighting candles during these days is a Rabbinic mitzva, just like reading the Megillah on Purim.
It is interesting that the Rambam refers to Chanuka as “yemei simcha - days of joy,” since the expression “joy” when used in halachic context usually denotes celebratory feasts, such as those held on Yom Tov and Purim. However, the Gemara implies that Chanuka is a time for hallel and hoda’ah (praise), not joyous feasting. What then is the nature of the joy that the Rambam associates with Chanukah?
To explain, we begin with the Beis Yosef’s famous question of why Chanuka is celebrated for eight days. Since the vessel contained enough oil to burn for one night under normal circumstances, only the following seven nights were miraculous. Therefore, Chanukah should be celebrated for only seven day, in memory of the seven miraculous nights.
The Meshech Chochma answers both questions in his explanation of the verse:
וביום שמחתכם ובמועדיכם ובראשי חדשיכם ותקעתם בחצצרת על עלתיכם ועל זבחי שלמיכם.
On the days of your rejoicing, on your festivals and your Roshei Chodoshim, you shall blow trumpets when offering your olah and shlamim sacrifices.
The Meshech Chochma explains that the “days of your rejoicing” refer to the inauguration of the Mizbei’ach. To support this point, he cites sources throughout Tanach, where we find that whenever the Mizbei’ach was repaired, the Kohanim would blow upon trumpets, causing the nation to rejoice. So too, after the Greeks defiled the Mizbei’ach, the Chashmonaim were forced to repair and resanctify it with eight days of inauguration. In memory of this event, we rejoice for eight days of Chanukah.
The Rema also suggests that Chanukah commemorates not only the miracle of the Menorah, but also the reinauguration of the Mizbei’ach. Accordingly, the Rema justifies the custom to have festive meals on Chanukah, in commemoration of the Mizbei’ach; while the hallel and hoda’ah mentioned in the Gemara commemorate the miracle of the Menorah.
However, the Rambam does not seem to concur with these opinions, since he mentions only the miracle of the Menorah, but ignores entirely the reinauguration of the Mizbei’ach. The Gemara also makes no mention of this second aspect of Chanukah, but attributes the holiday solely to the victory of the Chashmonaim and the miracle of the Menorah. Therefore, perhaps a different explanation for the Rambam must be sought.
A Sign of Hope
After the Chashmonaim defeated the Greeks and recaptured the Beis HaMikdash, Hashem provided them with the miracle of the Menorah as a sign of hope and encouragement. Why did He choose specifically the Menorah with which to perform a miracle, rather than the Mizbei’ach or the Table? What was the significance of this miracle, and what was it meant to teach us?
The period of time preceding the Chanukah story was one of great difficulty for the Jewish people. The Jews were faced with a twofold challenge, from the harsh decrees of the Greeks from without, and the pernicious influence of the Hellenistic Jews from within, both of which served to breach the walls of our identity as Hashem’s chosen nation.
In the war of the Chashmonaim to restore Jewish identity, many Jews were killed, including two of Matisyahu’s sons, yet they ultimately succeeded in freeing the Beis HaMikdash from the hands of the Greeks. As they cleansed the Beis HaMikdash from the vestiges of Greek defilement, they prayed for a sign that their war had indeed been justified; that the Jewish blood spilled in their conflict had not been lost in vain. They hoped for a miracle, which would silence the Hellenistic Jews from their arguments to draw Jews away from the faith of our forefathers, by proving incontrovertibly that the Shechinah had returned to dwell among them.
The sign appeared in the form of the vessel that contained only enough oil to burn for one night, yet miraculously burned for eight. This paralleled the miracle that regularly occurred in the first Beis HaMikdash, in which the ner ma’aravi (western candle) was filled with the same amount of oil as the other six, yet burned throughout the night and the following day, until it was used to relight the other candles the following night. Our Sages refer to this miracle as “testimony before the entire world, that the Shechinah dwells among Israel.” For this reason, the miracle of Chanukah was performed specifically with the Menorah, to reenact the miracle of the ner ma’aravi.
Accordingly, the miracle of the oil burning for eight nights was the completion of the reinauguration of the Beis HaMikdash, since it showed that Hashem favored their efforts, and intended to dwell once again in the Beis HaMikdash, as a result of the sacrifice of the Chashmonaim and their supporters.
The Pnei Yehoshua also points to the miracle of the Chanukah, as a clear sign of Hashem’s love for His precious children:
לכך נראה דעיקר הנס לא נעשה אלא להודיע להם חיבת המקום עליהם כדאשכחן שנעשה להם הנס תמיד שלא נמצא פסול בעומר ובשתי הלחם. והואיל ואיתרחיש להו ניסא בעיקר הענין שנגאלו גאולה שלימה מיד מלכות יון הרשעה שהיו אומרים לישראל כתבו לכם על קרן השור שאין לכם חלק באלקי ישראל וגזרו כמה שמדיות ועכשיו שנגאלו ונעשה להם נס גדול ששלטו בשונאיהם, לכך נעשה להם גם כן נס זה בענין הנרות שהוא עדות לישראל שהשכינה שורה בהם כדדרשי נמי לענין נר מערבי אלא שלאחר מיתת שמעון הצדיק אפילו נר מערבי לפעמים היה כבה והולך לכך נעשה להם נס בזה הענין ממש באותן הימים שהיו עת רצון להודיע שחזרו לחיבתן הראשונה, כך נראה לי נכון.
The miracle of the Menorah was performed only to reveal Hashem’s love for Bnei Yisrael, reminiscent of the constant miracles [that had previously occurred in the Beis HaMikdash such as] that the omer and shtei halechem korbanos were never found unfit. The primary miracle was their redemption from the hands of the wicked Greeks, who forced them to engrave on the horns of bulls that they have no portion in the G‑d of Israel, and made many other harsh decrees against our religion.
After the great miracle of their redemption and their victory over their enemies, they witnessed a second miracle: that of the Menorah, which served as a testimony for Israel that the Shechinah had returned to dwell among them. This paralleled the miracle that once occurred with the ner ma’aravi. After the death of Shimon HaTzaddik, the ner ma’aravi occasionally burned out. However, Hashem made for them this parallel miracle at the auspicious occasion of their victory, to reveal that His love for them was as strong as ever.
Hashem’s assurance of His love for us and His intention to dwell among us are the greatest possible reasons for rejoicing. Therefore, it is quite clear why the Rambam refers to Chanukah as days of joy and hallel.
 Rambam, Hilchos Chanukah 1:1-3
 Bamidbar 10:10
 Shabbos 22b