Preheat oven to 350°.
Remove white papery skins from garlic heads (do not peel or separate cloves). Wrap each head separately in foil. Bake at 350° for 1 hour; cool 10 minutes. Separate cloves; squeeze to extract garlic pulp (you should have about 1/4 cup). Discard skins.
Preheat oven to 375°.
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 milk, 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 mixture over potatoes. Repeat procedure with remaining potato slices and shallot mixture, ending with potato slices. Pour milk mixture evenly over potatoes.
Cover with foil; bake at 375° for 30 minutes. Remove foil; bake, uncovered, 30 minutes. Sprinkle with cheese; bake 15 minutes or until cheese is golden. Let stand 10 minutes before serving.