Preheat oven to 450°. In a medium saucepan over medium heat, heat oil. Add sausage and cook, breaking up into small pieces with a wooden spoon, until golden, about 8 minutes. Add garlic and red pepper flakes to sausage and cook, stirring until fragrant, about 30 seconds.
Stir in tomatoes and basil and bring to a boil. Reduce to a simmer, and cook, stirring occasionally until sauce is thickened slightly, about 15 minutes. Season with salt and pepper. Remove from heat.
Bring a large pot of salted water to a boil. Cook pasta until al dente, about 2 minutes less than package instructions; drain.
Meanwhile, in a small bowl, lightly beat egg. Stir in ricotta, ½ cup Parmesan, and ½ cup mozzarella into the egg. Season with salt and pepper.
Spread a thin layer of the tomato sauce in a 2-quart baking dish. Arrange penne on top of tomato sauce in an even layer and dollop with ricotta mixture and remaining sauce. Sprinkle with remaining ½ cup Parmesan and remaining 1 cup mozzarella.
Bake mostaccioli until top is deeply golden and sauce is bubbling, about 15 minutes. Garnish with basil before serving.
