Preheat the oven to 400°F (200°C).
Peel away the loose, papery layers from each head of garlic, keeping the heads intact. Slice about ¼ inch off the top of each head to expose the tops of the garlic cloves. Set aside.
In a large (12-inch), oven-safe skillet, add the onion, mushrooms, and baby spinach. Gently toss to combine.
Nestle the garlic heads, cut side up, into the center of the skillet among the vegetables.
Drizzle olive oil evenly over the garlic and vegetables. Sprinkle with salt, pepper, and crushed red pepper flakes, if using.
Scatter the cubed cream cheese evenly throughout the skillet. Pour the heavy whipping cream over everything.
Cover the skillet tightly with aluminum foil and bake for 50 minutes.
Remove the foil and continue baking, uncovered, for 10 more minutes, until the mushrooms are golden and the garlic is very soft.
Carefully remove the skillet from the oven. Using tongs or a fork to hold the garlic heads, squeeze the roasted garlic cloves from their skins directly into the skillet. Discard the garlic skins.
Stir everything together until the cream cheese is completely melted and the sauce is smooth and creamy.
Add the cooked cavatappi pasta and freshly grated Parmesan cheese to the skillet. Gently stir until the pasta is fully coated in the sauce.
If the sauce is too thick, stir in a bit of the reserved pasta water, a little at a time, until it reaches your desired consistency. Start with ¼ cup and adjust as needed.
Serve warm, topped with chopped fresh parsley and extra Parmesan cheese, if desired.