Heat the oven to 375 degrees F and lightly grease a 9x13-inch baking dish. Bring a large pot of heavily salted water to a boil and cook the mostaccioli 2 to 3 minutes less than the package directions. Drain and set aside.
While the pasta cooks, heat the olive oil in a large deep skillet or Dutch oven over medium-high heat. Add the sausage, breaking it into small crumbles, and cook 6 to 8 minutes until browned and cooked through. Add the chopped onion and cook 3 to 5 minutes until soft. Stir in the garlic and red pepper flakes and cook 30 seconds until fragrant. Drain off any excess fat.
Pour both jars of marinara into the skillet with the sausage. Stir in the salt and black pepper, reduce the heat to low, and simmer 10 minutes.
In a medium bowl, stir together the ricotta, egg, 1/4 cup of the Parmesan, and Italian seasoning until smooth.
Add the drained pasta to the skillet of sauce and toss until coated. Stir in 1 cup of the mozzarella. Spread half the pasta mixture into the prepared baking dish, dollop the ricotta filling over the top and spread gently, then add the remaining pasta mixture. Sprinkle with the remaining 1 cup of mozzarella and the remaining 1/4 cup of Parmesan.
Cover loosely with foil and bake at 375 degrees F for 20 minutes, then uncover and bake 10 to 15 minutes more until the cheese is melted, golden, and bubbling. Let rest 10 minutes, scatter the fresh basil over the top, and serve.