Preheat your oven to 375°F (190°C).
Grease the baking dish with the unsalted butter.
Peel the sweet potatoes and slice them thinly using a mandoline slicer or a sharp knife (about ⅛ inch thick).
In a mixing bowl, combine the heavy cream, minced garlic, thyme, salt, and black pepper. Whisk until blended.
Arrange a layer of sweet potato slices at the bottom of the greased baking dish, slightly overlapping them.
Pour a portion of the cream mixture over the sweet potato layer, ensuring it's well coated. Sprinkle some Gruyère and Parmesan cheese on top.
Repeat the layering process until all sweet potatoes, cream mixture, and cheeses are used, ending with a cheese layer on top.
Cover the baking dish with aluminum foil and bake in the preheated oven for 40 minutes.
Remove the foil and bake for an additional 10 minutes, or until the top is golden brown and bubbly.
Allow the gratin to cool for a few minutes before serving.