Preheat the oven to 350°F (175°C).
Cook the spaghetti in a large pot according to the package directions until al dente, then drain and set aside.
Spoon a light layer of spaghetti sauce over the bottom of a 9×13-inch casserole dish.
Add a layer of cooked spaghetti over the sauce, then sprinkle a light layer of mozzarella and arrange some pepperoni on top.
Repeat layering noodles, sauce, cheese, and pepperoni until the dish is full, finishing with cheese and pepperoni on top.
Bake at 350°F (175°C) 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 begins to brown, watching closely to avoid burning the pepperoni.
Blot any excess grease from the top with a napkin, slice, and serve.