Preheat your oven to 375°F and grease a 9x9-inch or similar baking dish.
Melt butter in a medium saucepan over medium heat. Whisk in the flour and cook for about 1 minute.
Gradually whisk in the milk. Add garlic powder, onion powder, salt, and pepper. Cook until thickened, about 3–5 minutes.
Remove from heat and stir in both cheeses until melted and smooth.
Layer half of the sliced potatoes in the baking dish. Pour half of the cheese sauce over the top.
Repeat with the remaining potatoes and cheese sauce. Sprinkle fresh thyme over the top if using.
Cover with foil and bake for 45 minutes. Uncover and bake an additional 20–25 minutes until golden and bubbly.
Let rest for 10 minutes before serving.