Preheat oven to 375°. Heap squash on a rimmed baking sheet, drizzle with oil and 1/2 tsp. each salt and pepper, and toss to coat. Bake, stirring occasionally, until tender and golden brown, about 35 minutes. Transfer to a bowl.
Melt 2 tbsp. butter in a large frying pan over medium heat. Add leeks with 1/4 tsp. salt; cook until softened. Add garlic, cook 2 minutes, and add mixture to squash.
Melt remaining 2 tbsp. butter in same pan over medium heat. Add mushrooms and 1/4 tsp. each salt and pepper. Increase heat to medium-high and cook, stirring, until mushrooms have released their liquid and are beginning to brown, about 6 minutes. Remove from heat and stir in thyme.
Add mushrooms to squash-leek mixture. Stir in bread; scoop into a buttered 9- by 13-in. baking dish.
Whisk together half-and-half, eggs, remaining 1/2 tsp. salt and 1/4 tsp. pepper, the flour, and parmesan in a medium bowl. Pour custard over bread mixture and let stand 10 minutes. Top with gruyère, then bake, uncovered, until cheese is melted and beginning to brown and custard is just set (poke with a knife to check), 30 to 35 minutes.
Make ahead: Through step 4, 1 day ahead, covered and chilled; or finish bread pudding 1 day ahead, chill, and reheat at 375° for 30 minutes.