Preheat the oven to 375°F (190°C) with the rack in the middle position. Grease a 9x13-inch (23x33 cm) baking dish with cooking spray or softened butter, coating the sides and bottom thoroughly.
Peel and rinse the potatoes, then slice into thin, uniform 1/8-inch (3 mm) rounds using a mandoline or sharp knife. Soak in cold water to prevent browning, then drain and pat completely dry before layering.
Cut the cooked ham into 1/2-inch (1.3 cm) cubes and measure out 2 cups (300 g). If the ham has a sugary glaze, rinse and pat dry before using.
Melt 4 tablespoons butter in a large saucepan over medium heat. Add the diced onion and cook for 4-5 minutes until soft and translucent, then add the minced garlic and stir for 60 seconds until fragrant.
Sprinkle the flour over the onion and garlic mixture and stir constantly for 2 full minutes to cook out the raw flour taste. The mixture will look clumpy and paste-like.
Gradually whisk in the warmed milk in a slow, steady stream, then pour in the chicken broth and whisk to combine. Add the salt, pepper, dry mustard, thyme, and onion powder, then bring to a gentle boil, whisking frequently, and cook for 1 full minute until thickened.
Remove the saucepan from the heat and stir in 1 cup (113 g) of the shredded cheddar until completely melted and smooth. Taste the sauce and adjust seasoning with salt and pepper as needed.
Spread a thin layer of cream sauce across the bottom of the prepared baking dish, then layer one-third of the potato slices, one-third of the diced ham, and one-third of the sauce. Repeat two more times, ending with the final layer of sauce on top.
Scatter the remaining 1 cup (113 g) of shredded cheddar evenly over the top of the casserole, then finish with the grated Parmesan for a golden crust.
Cover the dish tightly with foil (lightly sprayed on the underside) and bake for 50-60 minutes, until the potatoes are nearly tender when tested with the tip of a knife.
Remove the foil and bake for an additional 20-30 minutes, until the top is deeply golden brown and bubbling around the edges. Watch closely during the last 10 minutes to avoid overbrowning.
Transfer the casserole to a wire rack and rest for at least 15 minutes before serving so the sauce sets properly. Garnish with fresh chopped parsley if desired and serve warm.