Heat oven to 350 degrees. Butter a 9x13 baking dish and set aside.
In a medium-size pot, melt butter. Add onion and cook for 5 minutes until translucent. Add garlic and cook for 1 minute. Sprinkle in flour, stir to combine, and continue to cook for 1-2 minutes.
Carefully pour in the stock and whisk to combine with flour mixture. Add in the milk, salt, and pepper, whisking all together. Bring the mixture up to a simmer and continue to whisk until sauce has thickened. Remove from heat.
Layer half of the potatoes in the prepared dish. Sprinkle on half of the thyme and Parmesan cheese. Ladle over half of sauce and repeat layer of potatoes, remaining sauce, thyme, and cheese. Cover with foil and bake for 30 minutes.
Remove foil and continue to cook for 30 minutes until bubbly around the edges. Set oven to broil and cook for 1 to 2 minutes until potatoes are golden brown on the top.
Remove from the oven and let rest for 10 minutes. Season with additional salt and pepper if desired and serve.