Pat thawed hashbrowns dry with a towel and set aside.
Preheat oven to 375°F and butter a 9x13-inch baking dish.
Sauté onion in 2 tbsp butter over medium heat until soft, then add garlic for 30 seconds.
Melt 2 tbsp butter in the same pan, whisk in flour, cook 1 minute, then slowly whisk in milk until thickened.
Off heat, stir in sour cream, 2 cups cheddar, salt, and pepper.
Combine sauce with dried hashbrowns and spread into the prepared dish.
Toss remaining melted butter with crushed cornflakes and remaining cheddar; scatter over top.
Bake 40-45 minutes until golden and bubbling. Rest 5 minutes before serving.