Cook spinach in 2 batches in 1 inch of boiling water in an 8-quart pot, stirring constantly, until wilted, 1 to 2 minutes. Drain in a colander and rinse under cold running water until cool. Squeeze small handfuls of spinach to remove as much moisture as possible, then reserve.
Rinse out pot and place over medium-low heat. Melt the butter, then add the shallots and garlic, stirring occasionally, until softened, about 4 minutes. Whisk in sweet white rice flour and cook roux, whisking, 3 minutes. Add milk in a fast stream, whisking constantly to prevent lumps, and simmer, whisking, until thickened, 3 to 4 minutes. Stir in cream cheese, salt, pepper, nutmeg ¼ cup of the grated Gruyere and cook, stirring, until cheese has melted, about 3 to 4 minutes.
Add spinach, stir to combine, then pour mixture into a 1 quart gratin dish. Top with remaining cheese, then bake for 35 to 40 minutes, until the cheese melts and begins to brown.
Recipe by Allons-Eat! at https://www.allonseat.com/creamed-spinach-gratin/