Preheat the oven to 350°F (175°C).
Cook the spaghetti according to package instructions until al dente.
In a large skillet, heat a little oil over medium heat and add the diced onion and minced garlic.
Add the shredded chicken to the skillet and mix well with the onions and garlic.
Stir in the crushed tomatoes and Italian seasoning; season with salt and pepper.
Combine the cooked spaghetti in the skillet with the chicken sauce mixture.
Transfer the mixture into a greased casserole dish, spreading it evenly.
Top with shredded mozzarella and grated Parmesan cheese.
Cover the dish with aluminum foil and bake for 25 minutes.
Remove the foil and bake for an additional 15 minutes until the cheese is bubbly and golden brown.
Let the casserole cool slightly before serving.