Start by melting butter in a saucepan over medium-low heat, then add thyme and garlic and cook gently until fragrant.
Sprinkle in the flour gradually while whisking continuously and cook briefly to remove the raw flour taste.
Slowly pour in the cream while whisking, allowing the mixture to smooth out and thicken into a rich sauce.
Let it simmer gently until it coats the back of a spoon, then remove from heat and stir in part of the cheeses until melted and smooth. Season with salt and pepper.
Arrange a layer of thinly sliced potatoes in a baking dish, then spoon some of the cheese sauce over the top and sprinkle with a portion of the remaining cheese.
Continue layering the potatoes, sauce, and cheese until the dish is filled, finishing with a generous layer of cheese on top.
Cover the dish with foil and bake in a preheated oven at 350°F until the potatoes are tender.
Remove the foil and continue baking until the top turns golden brown and bubbly.
Allow the dish to rest briefly before serving so the sauce can settle and thicken.