Federer saved six of seven break chances against the German after losing just two points on his serve in the first set.
After the match, Muguruza sent her best wishes to Williams.
During the changeover between sets, Williams called for a trainer, whose examination included a blood-pressure check, per reports. "It's really a weird feeling, because I don't feel like I won the match point and (got the) "well done, ... good match".
Serena Williams of the United States reacts while being interviewed after her defeat in the Women's Singles finals match to Naomi Osaka of Japan on Day Thirteen of the 2018 US Open at the USTA Billie Jean King National Tennis Center on September 8, 2018 in the Flushing neighborhood of the Queens borough of New York City. "I will focus on getting better and start preparing for Miami".
She is now ranked 10th in the world.
"Yeah, at the end of the first set, I felt that maybe she wasn't feeling well", said Muguruza (via the Palm Springs Desert Sun), who is ranked 20th.
Thousands strike in Spain, mark International Women's Day
Every year International Women's Day becomes pinker, glossier and more about gimmicks and discounts than collective power. Kenyan women shout slogans during a march to mark International Women's Day in Nairobi, Kenya, Friday March 8, 2019.
Halep, the 2015 champion, was challenged but got past qualifier Kateryna Kozlova 7-6 (7-3) 7-5.
For her part, Muguruza says that she took no pleasure from her unconventional victory against one of the sport's all-time greats.
"It was really hard against her because I never played against her - it was a bit hard to get a rhythm", Halep said.
Muguruza was winning 6-3 1-0 when Williams was forced to withdraw from the third round meeting. The opening set tie-break ended 12-10 with both players keen to put themselves ahead in the match.
Muguruza next faces seventh seed Kiki Bertens, who beat Britain's Johanna Konta.