To blanch the green beans, place water and a pinch of salt in a large pot over medium-high heat. Bring it to a boil.
Meanwhile, fill a large bowl with ice and water. Set it aside.
Carefully add the green beans to the boiling water. Cook until crisp and tender, 5-7 minutes.
Using a slotted spoon or a spider strainer, transfer the green beans into the ice water. Let them cool to room temperature for about 5 minutes. Drain.
Spread out the blanched green beans on a clean kitchen towel and pat dry as much as you can.
Preheat the oven to 375 degrees F. Butter the casserole dish with a tablespoon of butter and set it aside.
In the large skillet, melt the rest of the butter over medium heat. Add the garlic and saute for 30 seconds.
Add the flour and whisk constantly until lightly browned, for about 5 minutes.
While continuously whisking, gradually pour in the stock, followed by the heavy cream (again while gradually pouring), until thickened for about 10 minutes. Adjust the heat as necessary to avoid burning.
Off the heat, whisk in the cheddar cheese, parmesan, thyme, nutmeg, kosher salt, pepper, and red pepper flakes (if using).
Fold in the green beans and toss until they are evenly coated with the sauce.
Transfer the green beans to the prepared casserole dish and spread it out evenly.
Bake in the preheated oven for 10 minutes. Then, sprinkle the fried onion rings over the top of the casserole dish and bake for an additional 5 minutes until the fried onion rings are golden brown.
Serve.