Preheat oven to 325° F. Slice 1 garlic clove in half and rub the inside of a shallow baking dish with the cut sides. Spread the unsalted butter completely over the inside of dish.
In a small saucepan, bring the quartered shallots, cream, salt, pepper, 1 tablespoon of thyme, and the remaining 4 garlic cloves to a simmer in a small saucepan over low heat. Cook until the shallots and garlic are very soft, about 15–20 minutes. Let cool slightly. Transfer to a blender; blend until smooth.
Layer the potato slices in the prepared dish. Pour cream mixture over potatoes and cover dish tightly with foil. Bake potatoes until tender and creamy, about 60 minutes. Let cool.
Place rack in highest position; heat broiler. Remove foil and top the 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.