1. In a 2- to 3-quart pan over high heat, bring 4 to 6 cups water to a boil.
2. Cut squash into 1-inch chunks. Add to boiling water, cover, and simmer until tender when pierced, 12 to 14 minutes. Drain and mash squash with a potato masher or a mixer.
3. Meanwhile, cut off and discard tough green tops, root ends, and coarse outer layer of leeks. Split leeks in half lengthwise and rinse well. Thinly slice.
4. In a 10- to 12-inch frying pan over medium-high heat, combine oil, leeks, and shallots. Stir often, until vegetables are limp, 5 to 7 minutes. Remove from heat.
5. Add mashed squash, nutmeg, 1/4 teaspoon salt, pepper, and egg; mix well. Spread in a shallow 1-quart casserole.
6. Bake, uncovered, in a 350° oven until lightly browned on top, about 45 minutes (35 minutes in a convection oven). Add salt to taste.