Preheat the oven to 350°F.
Lightly grease a 9x13-inch baking dish.
Prepare the pasta according to package directions until al dente.
Drain the cooked pasta and set it aside.
Cut the cooked chicken into small bite-sized pieces.
In a large skillet or saucepan, melt the butter over medium heat.
Add the finely chopped onion to the melted butter.
Cook the onion until softened and lightly translucent.
Add the minced garlic and cook briefly until fragrant.
Add the flour to the onion and garlic mixture.
Stir continuously until the flour is fully incorporated.
Cook the flour mixture for no more than 1 minute.
Add the milk and sour cream to the pan.
Whisk until the mixture is smooth and evenly combined.
Continue cooking over medium heat until the sauce begins to thicken.
Add 2 1/2 cups of the grated cheese, reserving the remaining 1/2 cup for the topping.
Stir until the cheese is fully melted and the sauce is smooth.
Add the cooked chicken and cooked pasta to the cheese sauce.
Season with red pepper flakes, salt, and black pepper.
Toss until the chicken and pasta are evenly coated with the sauce.
Transfer the mixture to the prepared 9x13-inch baking dish.
Spread the casserole mixture into an even layer.
Sprinkle the reserved 1/2 cup of grated cheese over the top.
Place the baking dish in the preheated oven.
Bake for 20 to 30 minutes, or until the casserole is hot and the cheese is melted and bubbling.
Remove the casserole from the oven.
Allow it to rest for several minutes before serving.
Serve warm.