Preheat the oven to 400 F. Spray a 13 x 9 baking dish (or another similar shallow 2 1/2 quart baking dish) with nonstick spray. Cook the spaghetti according to package directions. Drain.
Meanwhile, in a large, deep saucepan, melt the 2 tablespoons of the butter over medium-high heat. Add the onions and mushrooms, season with salt and pepper, and cook, stirring occasionally, for about 8 minutes until they are browned and any liquid they have released evaporates. Remove to a plate.
Return the skillet to medium heat and melt the remaining 4 tablespoons of the butter. Sprinkle over the flour and cook, stirring 1 to 2 minutes until the flour is incorporated and turns golden. Whisk in the sage, broth, milk, and sherry if using, and bring to a simmer, whisking frequently for about 4 minutes until the sauce thickens. Stir in 1/4 cup Parmesan cheese until well blended.
Add the cooked mushrooms and onions, drained pasta, chicken, pimentos, and parsley (if your pan is not big enough, you can mix it all together in a large mixing bowl). Transfer the mixture to the prepared baking dish, and sprinkle with the remaining 1/4 cup Parmesan and the Gruyere.
Bake for 15 to 20 minutes until bubbly and golden brown. Serve hot.
Notes
You can make the casserole and store it in the fridge for up to 2 days before baking.If you bring it to room temperature before baking, you will probably only have to add another 10 minutes or so (since the casserole won’t be warm before going into the oven, it will take a bit longer). You can also bake it straight from the fridge at 400 degrees, but add about 15 to 20 minutes to the cooking time.