Preheat your oven to 375°F (190°C).
Cook the penne pasta according to package instructions until al dente. Drain and set aside.
In a large skillet, heat the olive oil over medium heat. Add the diced onion and sauté for about 3-4 minutes until translucent. Add the minced garlic and cook for an additional minute.
Stir in the chopped spinach and cook until wilted, about 2-3 minutes. Remove from heat and let cool slightly.
In a large bowl, combine the ricotta cheese, half of the mozzarella cheese, half of the Parmesan cheese, egg, oregano, salt, black pepper, and red pepper flakes (if using). Mix well.
Add the cooked pasta and sautéed spinach mixture to the cheese mixture. Stir until everything is well combined.
Spread half of the marinara sauce on the bottom of a 9x13 inch baking dish. Pour the pasta and cheese mixture over the sauce, then top with the remaining marinara sauce.
Sprinkle the remaining mozzarella and Parmesan cheeses on top.
Cover the dish with aluminum foil and bake for 25 minutes. Remove the foil and bake for an additional 10-15 minutes, or until the cheese is bubbly and golden.
Let it cool for 5 minutes before serving.