Preheat your oven to 375°F (190°C) and lightly grease a 9x13-inch baking dish with olive oil or cooking spray.
Cook the penne pasta in a large pot of salted boiling water for 2 minutes less than the package directions specify for al dente, then drain and set aside; the pasta will finish cooking in the oven.
Heat the olive oil in a large skillet over medium heat, then add the onion and bell pepper and cook for 5 minutes until softened; add the zucchini and mushrooms and cook for another 7 minutes until the vegetables are tender and any liquid has evaporated.
Stir in the minced garlic, oregano, and red pepper flakes and cook for 1 minute until fragrant, then remove the skillet from the heat and stir in the marinara sauce and cooked pasta until everything is evenly coated.
In a medium bowl, mix together the ricotta cheese, beaten egg, chopped basil, 1 cup of the mozzarella cheese, Parmesan cheese, salt, and pepper until well combined.
Spread half of the pasta mixture into the prepared baking dish, then dollop the ricotta mixture evenly over the top and gently spread it into a layer; top with the remaining pasta mixture and sprinkle the remaining 1 cup of mozzarella cheese over everything.
Cover the dish with foil and bake for 20 minutes, then remove the foil and bake for another 15-20 minutes until the cheese is golden brown and the sauce is bubbling around the edges.
Let the pasta bake rest for 10 minutes before serving to allow the layers to set for easier slicing.