Preheat the oven to 400°F. Prepare a 9x13 inch baking dish with butter and set aside.
In a medium pot, melt the butter on medium heat. Add the shallots and garlic and cook until translucent and fragrant, about 3-5 minutes. Add the flour and stir with a wooden spoon until combined, about 2 minutes.
Add the milk and thyme to the pot, stir to combine, and bring to a simmer over medium-low heat, being careful not to burn the milk, about 5-7 minutes. Season with salt and pepper. Set aside.
Layer half of the sliced potatoes in the baking dish and top with ½ of the milk mixture. Top with all the parmesan cheese and ½ cup of the gouda cheese.
Add the remaining potato slices, and top with the rest of the milk mixture and the rest of the gouda cheese.
Cover tightly with foil and bake for 35 minutes. Remove the foil and bake uncovered for an additional 20 minutes, or until the potatoes are soft and cooked through. Switch oven to a high broil to crisp the potatoes for about 5 more minutes.
Let cool for 10-15 minutes to set, and serve warm, garnished with fresh thyme.
Storage: Store in an airtight container or cover the baking dish tightly with tin foil and place in the fridge. Scalloped potatoes will last 3-5 days after cooking.