Boil sweet potato cubes until tender, 15–20 minutes. Drain well.
While potatoes cook, melt 1 tbsp butter in a skillet and cook onions low and slow until deep brown, 20–25 minutes. Stir now and then.
Mash potatoes with milk, 2 tbsp butter, salt, pepper, and nutmeg until mostly smooth. Fold in half the Gruyère.
Spread mashed potatoes in a 9x13 dish. Top with caramelized onions, remaining Gruyère, and panko mixed with 1 tbsp melted butter.
Bake at 375°F (190°C) until bubbly and golden, 20–25 minutes. Let rest 5 minutes before serving.