Preheat your oven to 350°F and lightly grease a 9x13 inch baking dish. While the oven heats, peel the potatoes and slice them into thin 1/8-inch rounds—I recommend using a mandoline for consistency, which ensures even cooking. Dice the onion finely, cube the ham into 1/2-inch pieces, and shred the cheddar cheese. Have all ingredients measured and ready before you begin cooking the sauce.
Melt the butter in a medium saucepan over medium heat, then add the diced onion and cook for 3-4 minutes, stirring occasionally, until soft and translucent. Add the thyme and cook for another 30 seconds to release its aromatic oils. Sprinkle in the flour and stir constantly for 1-2 minutes to create a light roux—this cooks out the raw flour taste without browning it.
Gradually whisk in the milk and chicken broth to avoid lumps, stirring constantly until the mixture is smooth. Bring to a boil over medium-high heat and let it bubble for 1 minute to thicken slightly. Remove from heat and season generously with salt, pepper, and garlic powder. I like to taste and adjust the seasoning at this point—the sauce should be flavorful since it won't develop much more flavor in the oven.
Divide the sliced potatoes, diced ham, and the béchamel sauce from Step 3 into three equal portions. Start by spreading 1/3 of the potatoes evenly in the prepared baking dish, then layer 1/3 of the ham over the potatoes, followed by 1/3 of the sauce. Repeat this layering two more times, finishing with sauce on top. Ensure the potatoes are fully submerged in sauce to cook evenly.
Cover the baking dish tightly with foil and bake for 50 minutes. This initial covered time allows the potatoes to steam and soften without the top drying out. After 50 minutes, remove the foil and bake for an additional 25-35 minutes uncovered until the potatoes are completely tender when pierced with a fork and the top is golden brown.
About 15 minutes before the casserole finishes baking (roughly 10-20 minutes into the uncovered baking time), sprinkle the shredded cheddar cheese evenly over the top. Return to the oven and bake until the cheese is melted and lightly golden. The cheese adds richness and creates a delicious crust on top.
Remove the casserole from the oven and let it rest for 15 minutes before serving. This resting period allows the layers to set slightly and makes it easier to portion without falling apart. The dish will be piping hot and the flavors will have melded together beautifully.