Preheat the oven to 350°F (175°C). Bring a large pot of water to a boil and cook the ziti (or penne or gluten-free pasta) in salted water according to package instructions until just al dente. Drain and set aside.
While the pasta cooks, heat a deep pan or Dutch oven over medium-high heat. Add the ground beef and chopped onion and cook, breaking up the beef with a spatula, until the beef is fully cooked and the onion is softened, about 5–7 minutes.
Add the minced garlic, 1 teaspoon salt, and 1/2 teaspoon black pepper to the pan. Sauté for about 1 minute until fragrant.
Pour in the 5 cups marinara sauce, bring the mixture to a simmer, and continue cooking for 5 minutes. Turn off the heat.
Chop the basil leaves and set aside a few whole leaves for garnish if desired. Stir the chopped basil and the 15 ounces ricotta into the sauce until combined.
Add the cooked, drained pasta to the sauce and ricotta mixture. Stir gently just until the noodles are coated and the ricotta is distributed (do not overmix).
Spoon a ladleful of the meat sauce into the bottom of a 9×13-inch casserole dish to lightly coat the bottom.
Transfer half of the pasta mixture into the casserole dish. Top with half of the shredded mozzarella and half of the grated Parmesan.
Add the remaining pasta mixture to the dish, then top with the remaining shredded mozzarella and remaining grated Parmesan.
Wipe any sauce or cheese from the rim and edges of the dish to help prevent burning at the edges.
Bake uncovered at 350°F for 25 minutes. If you want browned cheese on top, switch the oven to broil and broil for 1–2 minutes, watching closely so it does not burn.
Remove from the oven and let stand for 5 minutes. Garnish with the reserved basil leaves, if desired, then serve.