If using fresh spinach, bring 1 inch water to a boil in a 6- to 8-quart pot over high heat. Add spinach, a few handfuls at a time, and cook, turning with tongs, until wilted, 3 to 5 minutes. Drain in a colander and rinse under cold water.
Thoroughly squeeze cooked fresh or thawed frozen spinach in small handfuls to remove excess moisture, then coarsely chop and transfer to a bowl.
Melt 3 tablespoons butter in an 8-inch heavy skillet over moderately low heat, then cook onion and garlic, stirring, until softened, 3 to 5 minutes. Add onion mixture to spinach along with salt, pepper, nutmeg, and cream and stir to combine.
Put oven rack in upper third of oven and preheat oven to 400°F. Butter a 3-quart shallow baking dish (13 by 9 inches; not glass).
Cut squash to separate bulb section from solid neck section, then cut pieces lengthwise into 1/8-inch-thick slices with slicer.
Layer squash and spinach mixture in baking dish, using about one fifth of squash and one fourth of spinach for each layer, beginning and ending with squash. Sprinkle top layer of squash evenly with cheese and dot with remaining 2 tablespoons butter, then cover directly with a sheet of parchment or wax paper. Bake until squash is tender and filling is bubbling, 25 to 30 minutes. Remove paper and bake gratin until browned in spots, 10 to 15 minutes, or broil 3 inches from heat, 2 to 3 minutes.