Preheat the oven to 450 degrees F. Bring a large pot of salted water to a boil. Cook the cavatappi until very al dente, 2 to 3 minutes less than the label directs; drain.
Heat the olive oil in a large skillet over medium heat. Add the garlic and red pepper flakes and cook until the garlic is golden. Crush the plum tomatoes into the skillet with your hands; rinse out each can with 1/2 cup water and add the water to the skillet. Add the basil; simmer, uncovered, until the sauce is thickened, about 15 minutes. Discard the basil; season the sauce with salt. (Alternatively, heat 4 cups prepared tomato sauce.)
Stir the ricotta into the sauce, then add the artichoke hearts and fennel.
Brush a 3-to-4-quart baking dish with olive oil. Toss the cooked pasta with the sauce and half of each cheese. Spread in the prepared baking dish. Sprinkle the remaining cheese over the pasta. Bake, uncovered, until browned, about 15 minutes. Let rest 15 minutes before serving.