Start by bringing a large pot of salted water to a rolling boil. Cook the rigatoni until just al dente, since it will continue cooking in the oven. Drain well and toss lightly with olive oil to prevent sticking.
In a large bowl, combine ricotta cheese, pesto, minced garlic, Italian seasoning, black pepper, and red pepper flakes if using. Mix gently until everything is well blended and creamy.
Add the cooked rigatoni to the pesto-ricotta mixture. Stir slowly so the pasta gets evenly coated without breaking. This step ensures every bite is flavorful.
Transfer half of the pasta mixture into a greased baking dish. Sprinkle with a layer of mozzarella and parmesan, then add the remaining pasta and top with the rest of the cheese.
Place the dish in a preheated oven at 375°F (190°C). Bake uncovered until the cheese is melted, bubbly, and lightly golden on top.
Let the pasta bake rest for about 5 minutes before serving. This helps the layers set and makes serving much easier.