Heat the olive oil in a large pan over medium heat. Add the onions and saute until soft, 3 to 4 minutes. Add the garlic before the onions start browning a bit. If you'd like to make the sauce spicier, add a pinch of red pepper flakes.
Add the tomatoes and season with a pinch of salt and pepper. Simmer over medium-low heat until the sauce has a thickened. Strive for balance in the consistency of the sauce; it should be fluid but not overly wet, about 30 minutes.
For the polenta: Pour the oil in a 9-by-5-inch loaf pan and swirl to coat. Set aside.
Bring 6 cups of water to a boil in a large saucepan over high heat and add a big pinch of salt (follow the directions on the polenta package if they differ). Lower the heat to medium and gradually whisk in the polenta, stirring constantly. Continue cooking, stirring constantly, until the polenta thickens and pulls away from the sides of the pan, about 5 minutes. Transfer the polenta to the prepared loaf pan and let cool to room temperature, then place in the refrigerator for one hour.
To assemble: Heat the oven to 425 degrees F. Brush a 9-by-13-inch casserole dish with olive oil.
Turn the polenta out on a cutting board and slice into 1-inch slices.
Assemble the pasticciata in the following order: One layer of polenta, one layer of sauce, a generous sprinkle of grated mozzarella and another of Parmesan. Keep layering until there is no more polenta (about two layers), then top with a final layer of sauce and cheese. (Reserve a little Parmesan for serving.)
Bake for 20 to 25 minutes, then broil for a final 3 to 5 minutes to brown the cheese top and make it beautiful. Serve dressed with some olive oil, salt and pepper and a final touch of grated Parmesan.