The custom of eating an egg at the Seder is rooted in the general practice of serving eggs at a mourner's meal as a symbol of mourning, and the Rema (Orach Chayim 476:2) explicitly connects this to Pesach night, explaining that the night of Tisha B'av is calendrically fixed relative to the first night of Pesach, and also tying the egg to mourning for the destruction of the Temple where the korban Pesach was once offered.
This mourning-food custom is not unique to Pesach: the Shulchan Arukh (Yoreh De'ah 378:9) records that a mourner is first fed eggs or lentils as a symbol of mourning before eating his fill, establishing eggs as a standard mourner's food, and Rav Eliezer Melamed (Peninei Halakhah, Zemanim 9:3) similarly notes that mourners eat hard-boiled eggs because their round shape alludes to the cyclical nature of life, adding that there is no prohibition against eating two eggs.
The Mishnah Berurah (476:11-13) elaborates on the Rema, adding the Gra's reasoning that the egg also commemorates the chagigah offering described earlier in siman 473, and explains that since the zeroa is eaten roasted and roasted meat is forbidden at the Seder, the egg substitutes to preserve the chagigah remembrance; he notes that according to the reason tied to the destruction of the Temple the custom would also apply on the second night, and cautions that by all reasons the eggs eaten during the meal are only a secondary remembrance.
The Beit Yosef (Orach Chayim 476:4) discusses the related custom of eating cooked rather than roasted meat at the Seder meal as a sign that one is not eating roast, which is the backdrop against which the egg custom as a chagigah or mourning remembrance is understood.
Haggadah im Likkutei Taamim uMinhagim (סדר הגדה) explains that the zeroa and egg are the two cooked foods commemorating the korban Pesach and the chagigah, and it notes the custom of using an egg as a remembrance of mourning for the Temple, though it raises a question about the historical basis for that reason and discusses related practices in preparing and placing these items on the Seder plate.
Igros Moshe (OC 1:156) addresses this directly, ruling that eating an egg at the Seder is permitted despite its association with the chagigah offering, because the further association with mourning makes the chagigah-commemoration purpose less conspicuously invoked, and he cites the Gra's view that eating the egg is in fact required as a remembrance of the chagigah.
Igros Moshe (OC 1:155) adds that the two cooked foods at the Seder commemorate the korban Pesach and the chagigah offering, noting that Rav Yosef required two types of meat specifically, and observing that there appears to be no dissent regarding this commemorative function.
Mishneh Halachos (7:67) ties the four cups of the Seder to mourning and consolation for suffering endured by Avraham, Yitzchak, and Yaakov in Egypt, and on this basis suggests that the egg eaten specifically on Pesach night before the meal serves the same mourning-related purpose.