Preheat your oven to 375°F (190°C). Lightly grease a 9x13 inch baking dish with olive oil or cooking spray, coating the bottom and sides evenly, then set aside.
Bring a large pot of salted water to a boil, add the 12 oz spaghetti, and cook 1–2 minutes less than al dente (the pasta finishes cooking in the oven). Reserve 1/4 cup pasta water, drain, return pasta to pot, and toss with the 2 tablespoons of softened butter. Allow to cool 5 minutes.
Add the 2 lightly beaten eggs and 1/4 cup of the grated Parmesan to the cooled buttered spaghetti, tossing until every strand is well coated. Set aside while you make the meat sauce.
Heat 1 tablespoon olive oil in a large skillet over medium-high heat. Add the diced onion and cook 3–4 minutes until softened, then add the minced garlic and stir 30 seconds. Add the 1 lb ground beef and cook 7–9 minutes, breaking it apart, until fully browned. Drain excess grease.
To the browned beef, add the marinara sauce, drained diced tomatoes, Italian seasoning, oregano, salt, black pepper, and red pepper flakes (if using). Stir to combine and simmer over medium-low heat for 8–10 minutes until slightly thickened. Adjust seasoning to taste.
Spread a thin layer of meat sauce across the bottom of the baking dish. Add half the pasta, top with half the remaining sauce, then sprinkle 1 cup of mozzarella. Repeat with the remaining pasta and sauce, then finish with the remaining 1 cup of mozzarella and the rest of the Parmesan.
Cover the baking dish tightly with aluminum foil and bake in the preheated 375°F oven for 25 minutes.
Remove the foil and bake for an additional 15–20 minutes, until the cheese is melted, golden, and bubbling at the edges. For extra browning, broil for the last 2–3 minutes, watching closely.
Remove from the oven and let the casserole rest for 5–10 minutes before slicing. Garnish with fresh basil or parsley if desired and serve hot directly from the baking dish.