Preheat the oven to 375°F. Spray a 9×9-inch pan or 11×7-inch casserole dish with nonstick spray.
Bring a large pot of salted water to a boil. Add the 8 ounces spaghetti and cook according to package instructions until al dente. Drain the pasta well and set aside.
In a nonstick skillet over medium-high heat, add the 16 ounces ground beef and cook, breaking it up with a spoon, until browned and no longer pink (about 6–8 minutes). Spoon out and discard excess fat. Transfer the cooked beef to a bowl and set aside.
Wipe the skillet if desired, then return it to medium heat and add the 1 tablespoon olive oil. Add the ½ medium sweet onion, finely chopped, and sauté until softened, about 5 minutes.
Add the 3 minced garlic cloves to the onions and cook, stirring, for about 1 minute until fragrant.
Return the cooked beef to the skillet with the onions and garlic. Stir in the 24 ounces jarred marinara sauce, heat until warmed through, then remove the pan from the heat.
In a medium bowl, combine the 4 ounces ricotta cheese, 4 ounces cream cheese, and ½ cup sour cream. Season with salt and pepper to taste and stir until the mixture is smooth and evenly combined.
Spread a thin layer of the meat sauce across the bottom of the prepared baking dish (just enough to cover the bottom).
Add half of the cooked spaghetti to the dish in an even layer. Spoon half of the remaining meat sauce over the spaghetti, then dollop and spread half of the ricotta mixture over the sauce. Sprinkle half of the 1½ cups shredded mozzarella cheese over the ricotta.
Repeat the layers: add the remaining spaghetti, spoon on the remaining meat sauce, spread the remaining ricotta mixture, and top with the remaining shredded mozzarella. Sprinkle the ½ cup grated Parmesan cheese evenly over the top.
Bake uncovered at 375°F for 25 minutes. Check the cheese—if it is browning too quickly, loosely cover the dish with foil. Continue baking another 15 to 20 minutes, until the casserole is hot and bubbly.
Remove from the oven and let rest a few minutes. Garnish with chopped fresh basil before serving.