Heat oven to 450° F. On a rimmed baking sheet, toss the squash with the bacon and onion. Roast, tossing occasionally, until tender, 30 to 35 minutes.
Meanwhile, cook the spaghetti according to the package directions. Drain, reserving 1 cup of the cooking water.
Toss the spaghetti with the squash mixture, pecorino, and reserved cooking water. Season with ¼ teaspoon each salt and pepper.