Preheat your oven to 375°F.
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.
Stir in the minced garlic and cook for an additional 1 minute.
Add the fresh spinach to the skillet 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, dried oregano, salt, black pepper, and red pepper flakes (if using).
Mix in the sautéed spinach and onion mixture, followed by the cooked penne pasta. Stir until well combined.
Spread half of the marinara sauce on the bottom of a 9x13 inch baking dish.
Pour the pasta mixture over the sauce and spread it evenly.
Top with the remaining marinara sauce and sprinkle with the remaining mozzarella and Parmesan cheeses.
Cover the baking dish with aluminum foil and bake for 20 minutes.
Remove the foil and bake for an additional 15 minutes, or until the cheese is bubbly and golden.
Let the pasta bake cool for about 5 minutes before serving.