The world number one bossed the first set, but the 82-ranked Linette dominated the second and offered resistance in the third before the Spaniard won 6-2 1-6 6-4.
Barty failed to convert three match points in the third set but controlled the tie-break to seal the win.
Australian Ashleigh Barty continued her strong form at the Wuhan Open, beating her second consecutive top-20 player with a 4-6, 6-0, 6-4 win over ninth-seeded Agnieszka Radwanska in the third round yesterday.
Muguruza, who required treatment to that leg during a straight-sets win over Lesia Tsurenko on Tuesday, was very much second best in the second set as Polish outsider Linette hit back.
The 2015 Wuhan runner-up, Muguruza will maintain her hold the top spot if she beats Ostapenko and reaches her eighth semifinal of the season.
"I knew it would be a tough match, but I think I did the right preparations", the 22-year-old Sakkari said in her post-match press conference.
Accused Leaker Reality Winner Stuffed NSA Report in Her Pantyhose
They said victor had inserted a portable hard drive into a top-secret Air Force computer before she left the military past year . The recipient is redacted from the report but it was published by The Intercept .
The most dominant performance of the day came from third seed Karolina Pliskova, a 6-2 6-1 victor over Wang Qiang.
Muguruza got off to a flying start but Ostapenko turned things around and won the final six games in a 1-6 6-3 6-2 victory - her 19th three-set win of the season. She drops out of the Wuhan Open in the quarterfinals, losing to Ashleigh Barty in three sets. "I was serving very well the whole match, had a lot of aces, but [in the last] two games, I couldn't really serve for the match".
Two of 2017's grand slam champions will face off in the quarter-finals of the Wuhan Open.
Sixteenth seed Elena Vesnina lost in straight sets to qualifier Maria Sakkari of Greece 7-6 (6) 7-5.
Babos is 4/9 to defeat Aryna Sabalenka (13/8), who defeated Kateryna Kozlova 7-6 (7/5) 3-6 6-1 to reach her first ever WTA semi-final.