Preheat the oven to 350°F (175°C).
Bring a large pot of salted water to a boil and cook the spaghetti according to the package directions until al dente. Drain and set aside.
Spread a light layer of spaghetti sauce across the bottom of a 9×13 casserole dish.
Add a layer of cooked spaghetti over the sauce, then sprinkle a light layer of mozzarella, followed by a layer of pepperoni. Repeat layers (sauce, spaghetti, cheese, pepperoni) until ingredients are used and the dish is filled, finishing with cheese and pepperoni on top.
Bake in the preheated oven for 20–30 minutes, until the casserole is hot and bubbly.
If desired, switch the oven to broil and broil 2–5 minutes until the cheese and pepperoni begin to brown, watching closely to avoid burning.
Remove from the oven and blot the top of the pepperoni and cheese with a paper towel to absorb excess grease.
Let the casserole rest a few minutes, then serve.