Arrange a rack in the center of the oven; preheat to 350℉ (180℃). In a large pot of boiling salted water, cook green beans until bright green, 2 to 3 minutes. Using a spider or slotted spoon, transfer green beans to an ice bath. Drain beans; season with 1/2 tsp salt. Transfer to a 13" x 9" inch ( 33 x 23 x 5 cm) baking dish.
In a large skillet over medium heat, melt 2 TBSP butter. Add onion; season with salt. Cook, stirring occasionally, until softened and starting to brown, about 7 minutes.
Add 2 TBSP butter and let melt. Add mushrooms and cook, stirring occasionally, until liquid has evaporated and mushrooms are tender, 13 to 15 minutes. Add garlic and cook, stirring, until fragrant, about 1 minute more; season with salt. Transfer to a baking dish, spreading over the green beans.
In the same skillet over medium heat, melt the remaining 4 TBSP butter. Whisk in flour and cook, whisking, until roux is golden and smells toasted, 2 to 3 minutes. Slowly whisk in milk until combined, then whisk in broth. Add the thyme sprigs. Bring to a simmer and cook, stirring occasionally, until the sauce has thickened, 5 to 7 minutes. Stir in gnocchi, breaking apart any gnocchi that has stuck together. Remove thyme stems.
Pour sauce and gnocchi over bean mixture in baking dish. Stir to combine.
Bake casserole until edges are bubbling and gnocchi is warmed through, about 30 minutes. Top with fried onions, then continue to bake until onions are fragrant and warmed through, 7 to 10 minutes more.