In a 2- to 3-quart pan over high heat, bring 4 to 6 cups water to a boil.
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.
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.
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.
Add mashed squash, nutmeg, 1/4 teaspoon salt, pepper, and egg; mix well. Spread in a shallow 1-quart casserole.
Bake, uncovered, in a 350° oven until lightly browned on top, about 45 minutes (35 minutes in a convection oven). Add salt to taste.