Preheat oven to 375°. Cook pasta according to package directions.
Meanwhile, in a large skillet over medium heat, cook sausage and onion, crumbling meat, until sausage is no longer pink. Add garlic; cook 1 minute longer. Drain. Stir in pasta sauce and mushrooms. Bring to a boil. Reduce heat; cover and cook until heated through, about 15 minutes.
Drain pasta. Combine the egg with the next 5 ingredients. Spread 1 cup sausage mixture in a greased 13×9-in. baking dish. Top with spaghetti and remaining sausage mixture. Layer with egg mixture and mozzarella cheese.
Cover and bake 45 minutes. Uncover; bake until lightly browned and heated through, about 15 minutes longer. Let stand 15 minutes before cutting.