Preheat oven to 450 degrees F.
Remove white papery skins from garlic heads (do not peel or separate cloves). Place the heads on a sheet pan, covered with foil and drizzle with olive oil. Bake for 40 to 50 minutes; cool 10 minutes. Separate cloves; squeeze to extract garlic pulp (you should have about 1/4 cup). Discard skins.
Preheat oven to 375 degrees F.
Heat oil in a large nonstick skillet over medium-high heat. Add shallots; sauté 3 minutes or until softened. Add mushrooms; sauté 5 minutes. Stir in vinegar; cook 1 minute or until liquid almost evaporates. Remove from heat.
Place cream, garlic pulp, flour, thyme, salt, and pepper in a food processor; process until smooth.
Arrange one-third of potatoes in a 13 x 9-inch baking dish coated with cooking spray. Spread half of the shallot/mushroom mixture over potatoes. Repeat procedure with remaining potato slices and shallot mixture, ending with potato slices. Pour cream mixture evenly over potatoes.
Cover the baking dish and bake for 30 minutes. Remove foil; bake, uncovered, 30 minutes. Sprinkle with cheese; bake 15 minutes or until cheese is golden. Test for doneness by sticking a fork into the casserole. It should sink through easily. Let stand 10 minutes before serving.