Preheat the oven to 450°F. Spray a large baking dish with nonstick spray.
Bring a large pot of salted water to a boil. Cook the pasta until very al dente, about 7 minutes or half of the time indicated on the package. Reserve ¼ cup of the pasta water, then drain, rinse with cool water and set aside.
In a large bowl, whisk together the pumpkin, heavy cream and the reserved ¼ cup pasta water. Grate in the garlic cloves, then stir in 1 teaspoon salt, a few grinds of pepper, the thyme, red pepper flakes and nutmeg, if using. Stir in 1½ cups of the Gruyère, half of the Parmesan and the spinach, then add the pasta and stir to coat.
Transfer the mixture to the prepared baking dish. Top with the remaining cheese and dollop with ricotta. Transfer to the oven and bake until bubbly, 20 to 25 minutes.
