Heat the oven to 220 C / 425 F with a rack in the center. On a 33 x 46 cm / 13 x 18 inch rimmed sheet pan, toss the mushrooms and unpeeled garlic cloves with the olive oil, 1/2 tsp salt, pepper, and thyme. Spread everything in a single layer with a little space between pieces.
Roast for 25 minutes, flipping the mushrooms once at the 15-minute mark, until they're deep brown at the edges and shrunken by about a third. The garlic is done when a clove yields to a gentle squeeze.
While the pan roasts, bring 4 L / 4 quarts of water to a boil in a 5-quart / 4.7 L pot, 26 cm wide. Add 1 tbsp salt and the rigatoni or penne, then cook 1 minute short of the package time, usually 9 to 10 minutes. Scoop out 1 cup / 240 ml of pasta water, then drain.
Let the garlic cool for 2 minutes, then squeeze the soft cloves out of their skins into a small bowl. Mash with the softened butter until it forms a loose paste.
Return the drained pasta to the empty pot off the heat. Add the garlic butter, 1/2 cup / 120 ml of the pasta water, the lemon zest, lemon juice, and Parmesan, and toss for 1 minute until the sauce turns glossy and clings to the pasta. Loosen with more pasta water a tablespoon at a time if it looks tight. Fold in the roasted mushrooms, parsley, and red pepper flakes, taste for salt, and serve immediately.