Bring a large pot of salted water to a boil and cook the penne pasta according to package directions for al dente, then drain well and set aside.
While the pasta cooks, preheat your oven to 375°F (190°C) and heat the olive oil in a large skillet over medium heat. Add the chopped onion and cook for 5 minutes until softened, then add the garlic and cook for 1 more minute until fragrant.
Add the ground Italian sausage to the skillet, breaking it up with a wooden spoon, and cook for 7-8 minutes until it is no longer pink and is browned.
Stir in the crushed tomatoes, fresh basil, oregano, salt, black pepper, and red pepper flakes. Bring the sauce to a simmer, then reduce the heat and let it cook for 10 minutes to allow the flavors to meld.
In a large bowl, combine the drained pasta with the meat sauce and half of the mozzarella and Parmesan cheeses, stirring until everything is evenly incorporated.
Transfer half of the pasta mixture to a 9x13-inch baking dish. Spoon and spread the ricotta cheese in an even layer over the pasta, then top with the remaining pasta mixture.
Sprinkle the top evenly with the remaining mozzarella and Parmesan cheeses. Bake uncovered for 25-30 minutes, or until the cheese is melted and bubbly and the edges are lightly browned.
Let the casserole rest on a wire rack for 10 minutes before serving to allow it to set for easier slicing.