Set your oven to 375°F (190°C) and lightly coat a medium-sized baking dish with grease.
Peel and slice the sweet potatoes thinly (around 1/4-inch thick). A mandoline slicer is recommended for even slices.
In a medium saucepan, melt the vegan butter over medium heat, stirring occasionally.
Stir in the minced garlic and cook for about 1 minute until it becomes fragrant.
Gradually whisk in the plant-based milk, nutritional yeast, shredded vegan cheese, salt, pepper, and nutmeg (if using).
Keep stirring until the cheese melts and the sauce thickens a bit.
Spread a thin layer of the creamy sauce at the bottom of the greased baking dish.
Arrange a layer of sweet potato slices in an overlapping pattern.
Pour a portion of the creamy sauce over the sweet potatoes.
Repeat the layers, alternating sweet potatoes, and sauce, until all ingredients are used. Top it off with a final layer of sauce.
If desired, sprinkle gluten-free breadcrumbs and crushed walnuts over the top for a crunchy finish.
Place foil over the baking dish and bake for 30 minutes.
Remove the foil and bake for 15–20 minutes, or until the top is golden and bubbling.
Let the gratin rest for 10 minutes before serving to allow it to set. This helps the layers set, making it simpler to slice.