Heat the oven to 350°F with a rack in the middle. Butter a 9×13-inch baking dish, including the corners.
Peel 3 pounds Yukon Gold potatoes and slice them ⅛ inch thick. Set them aside in a bowl so they are ready to layer as soon as the sauce is finished.
Warm 3 cups whole milk until hot to the touch but not boiling. In a saucepan, melt 4 tablespoons unsalted butter over medium heat. Add 1 small finely chopped yellow onion and cook, stirring, until soft and translucent, 5 to 7 minutes. Stir in 2 minced garlic cloves and cook about 30 seconds, just until fragrant. Sprinkle in ¼ cup all-purpose flour and cook, stirring, for 1 minute. The roux should look pale, not browned.
While whisking constantly, add the warm milk a little at a time until the mixture is smooth, then whisk in ½ cup heavy cream. Cook over medium heat, stirring often, until the sauce thickens enough to coat a spoon, 4 to 6 minutes. It should barely bubble. Stir in 1¼ teaspoons kosher salt (about ¾ teaspoon if using table salt), ½ teaspoon black pepper, ½ teaspoon dried thyme (or 1 teaspoon fresh thyme leaves), and a pinch of ground nutmeg. Taste and adjust the salt.
Take the saucepan off the heat. Set aside about ½ cup of the shredded cheese for the top, then stir in the remaining Gruyère and cheddar until melted and smooth. Do not return the sauce to a boil.
Arrange half of the potato slices in the baking dish, overlapping them slightly. Pour half of the sauce over the layer and nudge it into the corners. Repeat with the remaining potatoes and the remaining sauce. Press the top layer down gently so the slices are mostly covered. Sprinkle the reserved cheese over the top.
Cover the dish tightly with foil. Bake for 50 to 55 minutes. Uncover and continue baking until the sauce is bubbling at the edges, the top is golden, a knife or fork slides through the potatoes in the center with little resistance, and an instant-read thermometer inserted in the middle reads 165°F, 15 to 20 minutes more (about 70 minutes in the oven total). FoodSafety.gov lists 165°F as the safe minimum for casseroles, meatless ones included. If the top browns before the center is ready, tent the dish loosely with foil.
Let the scalloped potatoes rest for 15 minutes before serving so the sauce can set. This rest is included in the 1-hour 55-minute total.