One of the tastier items on the Seder table is the Charoses. The Mishnah in Pesachim (.דף קי"ד) presents a dispute as to whether having Charoses at the table on Pesach night is a Mitzvah or not; it is certainly not required by the Torah, as no mention of it is made there. This dispute thus focuses simply on whether or not there exists a Mitzvah MideRabbanan to have Charoses. Everyone agrees, however, that in practice, one must have Charoses at the table, and the only argument is if it is a Mitzvah or not.
The Gemara (שם דף קט"ז.) asks, according to the view that it is not a Mitzvah, why we must have it at all, and answers that the Charoses is needed because of the "קפא." Rashi and the Rashbam (שם בד"ה משום) explain that this קפא is a very sharp tasting substance that is found in many vegetables, including some used for Maror, which can actually be poisonous. The Charoses thus serves, apparently, to weaken or even nullify the taste and the danger of this substance. The Gemara earlier (:שם דף קט"ו) discusses whether the Maror must actually be dipped into the Charoses or simply placed near it in order for this to work. The Rashbam (שם בד"ה צריך) and Tosafos (שם בד"ה קפא) quote Rabbeinu Chananel there that this קפא is actually a kind of worm found in vegetables, which although allowed to be eaten, is, as Tosafos concludes, unhealthy or dangerous; the Charoses somehow is able to destroy this worm by being in contact with or near it. According to this view, then, the purpose of Charoses is to prevent any medical danger that may develop from eating Maror.
The second view in the above Mishnah, however, holds that having Charoses is a Mitzvah (MideRabbanan), and the Gemara (שם דף קט"ז.) discusses the nature and purpose of this Mitzvah. One opinion is that the Charoses reminds us of the תפוח, a certain fruit. Rashi and the Rashbam (שם בד"ה זכר) explain this by referring to the Midrash on a Posuk in Shir HaShirim (ח:ה'), also cited in the Gemara in Sotah (דף י"א:), which indicates that the righteous Jewish women in Egypt would encourage their husbands, exhausted and frustrated by the difficult labor, to continue to have children and perpetuate the nation with faith that they would soon be redeemed. When they were ready to deliver their babies, they would go out to the fields to escape the detection of the Egyptians, who wanted to destroy all the Jewish babies, and give birth under the תפוח trees. To commemorate this righteousness and heroism, we have Charoses, a principle ingredient of which is תפוח.
It should be noted that although in modern Hebrew, תפוח usually means an apple, and apples are indeed a basic ingredient of Charoses in many Ashkenazic homes, in Biblical Hebrew, as pointed out by Tosafos in Shabbos (דף פ"ח. בד"ה פריו) and in Taanis (דף כ"ט: בד"ה של), תפוח refers to a citrus fruit, like an Esrog. In many Sephardic homes, therefore, apples are not used at all for Charoses; it would thus seem proper that even if one does use apples, one should also include some citrus fruit or citrus juice in one's Charoses, especially since the above Gemara in Pesachim (דף קט"ז.) states that the Charoses should have a pungent flavor.
A second opinion in this Gemara suggests that, presumably because of its texture, as the Meiri (לפסחים שם) implies, the Charoses commemorates the mortar with which the Jews had to work when building in Egypt; the Gemara seems to accept both opinions. Tosafos (שם בד"ה צריך) quotes a third opinion, found in the Yerushalmi in Pesachim (פרק י' הלכה ג', דף ע.), that the Charoses is to remind us of the blood, a reference either to the first of the ten plagues, as suggested by the Pnei Moshe (שם בד"ה צריכה), or to the spilled Jewish blood in Egypt, as suggested by the Korban HaEidah (שם בד"ה מילתיה).
Tosafos then notes a practical difference between these latter two opinions: if the Charoses is to commemorate the mortar, its consistency should be chunky and thick, like mortar, whereas if it's to commemorate the blood, it should be more of a liquid, like blood. Tosafos thus suggests that initially one should make it thick, like the mortar, and keep it that way until just before dipping the Maror into it. Then, one should add some wine and make it more of a liquid, thereby fulfilling both opinions. The Ramo (אורח חיים סימן תע"ג סעיף ה') rules that Charoses should first be made thick and then have wine added to it, although he doesn't say when to do this; the Chayei Adam (כלל ק"ל סעיף ד') writes explicitly like Tosafos that one should add the wine before dipping the Maror into the Charoses. He also points out (שם), as do the Magen Avraham (שם ס"ק ט"ו) and others, that when the first night of Pesach falls on Shabbos, one cannot mix the wine in during the Seder, but must do it beforehand, unless he does it in a specific way (עיין משנה ברורה שם ס"ק מ"ח ובסימן שכ"א ס"ק ס"ה-ס"ח).
The Rambam (פרק ז' מהל' חמץ ומצה הלכה י"א) rules in accordance with the above view that having Charoses is indeed a Mitzvah MideRabbanan; Tosafos in Pesachim (שם בד"ה תגרי) indicates that this seems to be the implication of the Gemara. The Kol Bo (סימן נ') implies that actually, both of the above views are correct: having Charoses is a Mitzvah, but it also serves to prevent the health danger posed by the קפא, as described above. The Pri Chadash (שם סימן תע"ג ס"ק ה') likewise suggests that even the view which holds that Charoses is a Mitzvah agrees that it is also necessary for the קפא problem, and he posits that this is also the view of the above cited Rambam. He notes later on, though, (סימן תע"ה ס"ק א') that this קפא is no longer a problem in our times, an idea pointed out as well by the Shulchan Aruch HaRav (שם סעיף י"א); we therefore have Charoses only because it's a Mitzvah.
The question is what exactly the Mitzvah of Charoses involves. The above discussions in the Gemara in Pesachim (דף קט"ו:-דף קט"ז.) focus only on a requirement to dip the Maror into the Charoses, for whatever the reason, but no mention is made of eating the Charoses. The aforementioned Rambam actually implies that simply bringing the Charoses to the Seder table is a Mitzvah. In his Peirush HaMishnayos on Pesachim (פרק י' משנה ג'), however, the Rambam writes that according to the view that having Charoses is a Mitzvah (which the Halacha accepts, as pointed out above), there is indeed a requirement to eat Charoses, and one must even make a Beracha (על אכילת חרוסת) before doing so. In his Mishnah Torah, though, he says nothing about this.
According to one version of the text of the Mordechai on this Sugya in Pesachim (בסדר של פסח, דף ל"ח: בדפי הרי"ף), one is actually required to eat a Kezayis of Charoses, but, as the Bigdei Yesha (שם אות י"ט) notes, this requirement is not mentioned by the other Poskim. The Vilna Gaon (ביאר הגר"א לסימן תע"א בד"ה ויש מחמירין) implies, however, that there may be some who hold this way, and based on this, he explains the practice quoted (and rejected) by the Ramo (שם סעיף ב') not to eat the kinds of fruit used for the Charoses on Erev Pesach, just as we don't eat Matzoh on Erev Pesach, in anticipation of the Mitzvah to eat it at night. The Shulchan Aruch (סימן תע"ה סעיף א') does not require one to eat the Charoses and indeed rules that after dipping the Maror into it, one should shake the Charoses off in order not to diminish the bitterness of the Maror. One may, of course, eat Charoses, if he wishes, as part of the meal.