Preheat oven to 425°F with racks in center and lower third positions.
Combine sliced onions, ½ cup water and 1 tablespoon oil in a large skillet. Cover and cook over medium-high heat, stirring occasionally, until the onions are softened and the water has evaporated, about 15 minutes.
Uncover and stir in 1 teaspoon thyme. Continue cooking over medium heat, stirring often, until the onions are deeply golden brown and jammy, 20 to 25 minutes, adding more water as needed if the skillet becomes dry.
Stir in 1½ tablespoons vinegar; cook, stirring constantly, until the liquid has evaporated, about 1 minute. Remove from heat and transfer the onions to a medium bowl.
Meanwhile, toss sliced potatoes with the remaining 1 tablespoon oil in a large bowl until well coated. Divide between 2 large rimmed baking sheets and spread into an even layer. Roast on the center and lower racks until tender and beginning to brown, 20 to 25 minutes, rotating the baking sheets top to bottom halfway through.
While the potatoes roast, whisk together 1½ cups milk, 1 cup broth, 3 tablespoons flour, ½ teaspoon each garlic powder, pepper and salt and the remaining 2 teaspoons thyme in a medium saucepan. Bring to a gentle simmer over medium heat; cook, whisking often, until thickened, about 5 minutes. Remove from heat.
Remove the potatoes from the oven and increase oven temperature to broil. Let stand until cool enough to handle, about 10 minutes.
Arrange half of the roasted potatoes in a 2-quart broiler-safe baking dish in an even layer. Spread half of the reserved onions (about ½ cup) over the potatoes. Top with half of the milk mixture (about 1¼ cups), ½ cup Gruyère and ¼ cup Parmesan. Repeat the layers with the remaining potatoes, onions, milk mixture and cheeses.
Broil on the center rack until bubbling and the cheese is beginning to brown, 5 to 7 minutes. Let stand for 10 minutes before serving. Garnish with additional thyme, if desired.
