Preheat the oven to 400° F. In a 9×13 inch baking dish, combine the zucchini, olive oil, garlic, shallots, thyme, Italian seasoning, chili flakes, salt, and pepper. Roast 15 minutes. Pull the zucchini out of the oven. To the same pan, add the corn, orzo, and pesto. Pour over 2 1/2 cups of water and stir to combine. Return the dish to the oven and bake for 12-15 minutes, until most of the water has cooked into the pasta, but not all of it. Stir the pasta around, then sprinkle over the cheeses. Bake another 10 minutes, until the cheese has melted and the sauce is bubbling. If there's a lot of oil from the pesto on top, drain off the excess. Top with fresh basil!: The oven should feel reliably hot, which ensures the zucchini roasts quickly and the orzo absorbs liquid without becoming gluey. You want a consistent 400° F so the initial roasting caramelizes the edges and draws out concentrated flavors. Commonly, ovens run slightly cool, so if you suspect that, preheat a bit longer and check with an oven thermometer.
In a 9×13 inch baking dish, combine the zucchini, olive oil, garlic, shallots, thyme, Italian seasoning, chili flakes, salt, and pepper: At this point you should smell the herb and oil mingling, and the garlic will be fragrant without cooked notes yet. Toss everything so the zucchini gets an even oil sheen, or you'll see uneven roasting patches. A frequent mistake is overcrowding the dish which steams instead of roasts, so spread the pieces out.
Roast 15 minutes: During roasting, watch for browned edges and a softened center in the zucchini . The sound is quiet aside from occasional bubbling of oil, and the aroma becomes nutty and sweet. If you roast too long, the squash will collapse and lose structure, so stick to fifteen minutes as your visual cue.
Pull the zucchini out of the oven: Once removed, the oven remains hot, and the zucchini should glisten and show light caramel spots. Letting it sit inside too long will keep cooking it further, which can make it mushy, so transfer promptly to the next step.
To the same pan, add the corn, orzo, and pesto: The contrast of bright corn kernels against the roasted zucchini is obvious visually, and the pesto brings a fragrant herbal punch. Stirring distributes the pesto and helps the orzo contact liquid later; a common slip is not mixing well enough so you find pockets of pesto rather than an even coating.
Pour over 2 1/2 cups of water and stir to combine: The orzo needs this measured liquid to hydrate without turning into mush. You should see the water mostly covering the pasta and a glossy sheen from the pesto . If you pour too much, the bake will be soupy; too little, and the pasta will stay undercooked. Stir thoroughly to deglaze any browned bits for added flavor.
Return the dish to the oven and bake for 12 to 15 minutes, until most of the water has cooked into the pasta, but not all of it: You will notice the surface look less watery and more thickened, with the orzo swelling. The sound is subdued, with gentle bubbling as the liquid reduces. Pull it when the surface appears tacky and the orzo is mostly tender, because the next steps finish cooking it. Overbaking here can dry the casserole before the cheeses go in.
Stir the pasta around, then sprinkle over the cheeses: After stirring, the texture should feel creamy and cohesive, and adding shredded cheeses creates an even blanket that will melt and bind the ingredients. Ensure the cheese is distributed so you get both cheesy pockets and a uniform top. A mistake is dumping cheese only in one area, which yields uneven melt and browning.
Bake another 10 minutes, until the cheese has melted and the sauce is bubbling: During this final bake you will hear gentle bubbling and see the cheese turn glossy, possibly with small golden spots. The bubbling indicates the sauce is hot through, and the edges may crisp slightly, adding texture. If you leave it too long, the top can overbrown and the orzo can become dry.
If there's a lot of oil from the pesto on top, drain off the excess: Visually inspect the surface and, if needed, tilt the pan carefully to pour off surplus oil or blot with a paper towel. Excess oil can mask flavors and make the casserole greasy, so removing a bit keeps the palate clean. Be cautious while draining hot oil to avoid burns.
Top with fresh basil: Fresh basil added at the end provides a bright scent and a fresh contrast to the warm, cheesy bake. The leaves should look vibrant and green; if they have already wilted, their flavor has softened. Add them just before serving for best color and fragrance.