Wash hands with soap and water for 20 seconds.
Preheat oven to 325°F.
Gently rub garlic under cold running water. Scrub the potatoe with a clean vegetable brush under cold running water.
Cut 1 garlic clove in half and rub the inside of a 3-qt. shallow baking dish with cut sides. Smear butter all over the inside of the dish.
Bring shallots, cream, salt, pepper, thyme, and remaining 4 garlic cloves to a simmer in a small saucepan over low heat; cook until shallots and garlic are very soft, 15–20 minutes. Let cool slightly. Transfer to a blender; blend until smooth.
While saucepan ingredients are cooking, slice the potatoes very thin with a mandoline or very sharp knife. Arrange potato slices in the prepared dish, fanning out a handful at a time and placing in the dish at an angle (this ensures every scoop will have tender potatoes from the bottom and crisp edges from the top). Shingle as you work until the bottom of the dish is covered. Tuck smaller slices into any gaps to fill.
Pour cream mixture over potatoes and cover dish tightly with foil.
Bake potatoes until tender and creamy, 60–75 minutes. Let cool for 15-30 minutes.
Place rack in highest position; heat broiler. Remove foil and top potatoes with Gruyère and Parmesan. Broil until cheese is bubbling and top of gratin is golden brown, 5–10 minutes. Serve topped with more thyme leaves.