Bring a large pot of salted water to a boil. Cook mostaccioli until al dente according to package directions (about 8 minutes). Drain and return to the pot, tossing with a drizzle of olive oil to prevent sticking.
While the pasta cooks, heat olive oil in a large skillet over medium-high heat. Add onion and cook until soft, 4 minutes. Add garlic, cook 30 seconds. Add ground beef, season with salt, pepper, and oregano. Cook, breaking up meat, until browned. Stir in crushed tomatoes and red pepper flakes. Simmer for 15 minutes, stirring occasionally. Adjust seasoning.
In a medium bowl, combine ricotta, ½ cup mozzarella, ¼ cup Parmesan, beaten egg, parsley, and a pinch of salt and pepper. Mix until smooth.
Preheat oven to 375°F (190°C). In the pot with drained pasta, fold in the cheese mixture until pasta is coated. Spread a thin layer of meat sauce on the bottom of a 9x13-inch baking dish. Add half the pasta mixture, top with half the remaining meat sauce. Repeat layers. Sprinkle the reserved 1 cup mozzarella and extra Parmesan on top.
Bake uncovered for 20–25 minutes until bubbly and the cheese is melted and lightly browned. If needed, broil for the last 2 minutes for a crispier top. Let rest 5 minutes before serving. Garnish with fresh basil.