Place a large pot of salted water over high heat. Bring the water to a boil, then add the gnocchi. Cook the gnocchi according to the package directions, then drain it into a colander when done.
While the gnocchi cooks, heat the olive oil over medium heat in a large skillet or low casserole (preferably oven-safe — Note 1). Once the oil starts to shimmer, add the mushrooms. Cook them for about 10 minutes, stirring every 2 to 3 minutes, until they're tender and browned.
Push the mushrooms to the side and add the garlic to the skillet. Sauté the garlic for about 1 minute, stirring constantly, until it becomes very fragrant.
Stir in the crushed tomatoes, sugar, salt, and red pepper flakes. Bring the sauce to a simmer and allow it to cook for about 10 minutes, stirring occasionally, until it thickens slightly.
Make the béchamel sauce while the tomato sauce simmers. Heat the olive oil in a small saucepan, then add the flour. Whisk the oil and flour together while you bring the mixture to a simmer. Let it cook for about 2 minutes, whisking constantly, until it darkens slightly.
Whisk in the milk and salt. Bring the mixture to a simmer and let it cook for about 4 to 5 minutes, whisking occasionally, until it thickens and becomes creamy. Remove the pot from heat.
Preheat the oven to 400°F.
Once the tomato sauce has finished simmering for 10 minutes, stir in the spinach. Let the sauce continue to simmer for 1 to 2 minutes, until the spinach wilts. Remove the skillet from heat. Stir in the basil, taste the sauce and add more salt if desired. Stir in the gnocchi.
If you did not use an oven-safe skillet, transfer the gnocchi to an oven-safe baking dish at this point. If your skillet is oven-safe, you can bake it right in the skillet. Give the béchamel sauce a quick whisk, then spread the mixture over the gnocchi, dropping it in large dollops. It won't completely cover the gnocchi, and this is fine (Note 2).
Bake the gnocchi uncovered for about 15 minutes, or until the sauce is bubbly.
Let the gnocchi sit for about 5 minutes when it comes out of the oven, then serve.