Preheat the oven to 400°F. Spray a 9×13-inch baking dish with cooking spray and set it aside.
Arrange the sweet potato slices in the baking dish, layering them slightly so they overlap.
In a medium saucepan, melt the butter over medium heat. Add the diced onin and minced garlic, cooking for 2–3 minutes until softened.
Lower the heat to medium-low and stir in the heavy whipping cream, Parmesan cheese, Gruyere cheese, kosher salt, and black pepper. Continue stirring until the cheese melts and the mixture becomes smooth. Remove from heat.
Evenly pour the cheese mixture over the sweet potatoes, ensuring the sauce reaches all layers. Cover the dish tightly with aluminum foil and bake for 30 minutes.
Remove the foil and bake uncovered for an additional 20–30 minutes, or until the sweet potatoes are tender and the top is lightly golden.
Let the dish rest for 5 minutes before serving.