Preheat the oven to 375°F. Grease a 9×13-inch baking dish with nonstick spray.
Brown the butter: Melt the butter in a medium saucepan over medium heat. Continue cooking, stirring frequently, until the butter begins to turn golden. Add the sage leaves during the last 1–2 minutes and cook until the leaves are crisp and the butter is golden brown and smells nutty. Transfer the sage leaves to a paper towel-lined plate and reserve for serving.
4 Tablespoons unsalted butter, 6 sage leaves
Make the cream sauce: Whisk the flour into the browned butter and cook for 1 minute. Slowly whisk in the milk and cream, then add the smashed whole garlic cloves, thyme, salt, pepper, and nutmeg, if using. Bring to a gentle simmer and cook for 3–5 minutes, stirring frequently, until the sauce lightly coats the back of a spoon. Remove the garlic and thyme stems or strain the sauce through a fine-mesh strainer into a bowl or measuring cup with a pour spout.
3 Tablespoons all-purpose flour, 1 cup whole milk, 2 cups heavy cream, 3 cloves garlic, 4-5 thyme sprigs, 1 teaspoon kosher salt, 1/4 teaspoon black pepper, Pinch of nutmeg
Layer the potatoes: Arrange half of the sweet potatoes in the bottom of the prepared baking dish. Top with half of the cream sauce and 3/4 cup of the Gruyère. Repeat with the remaining sweet potatoes and cream sauce. Top with the remaining 3/4 cup Gruyère and the Parmesan.
3 lbs sweet potatoes, 1 1/2 cups shredded Gruyère cheese, 1/2 cup grated Parmesan cheese
Bake: Cover the dish tightly with foil and bake for 25 minutes. Uncover and bake for 35–40 minutes, or until the potatoes are tender, the edges are bubbling, and the cheese on top is browned. If needed, broil for 1–2 minutes to brown the top, watching closely.
Rest and serve: Let rest for 20–30 minutes before topping with the reserved fried sage and serving.