The 34-year-old had been due to play his first competitive match since undergoing surgery on a knee injury in the wake of the Australian Open.
“I am very sorry that I have to pull out of the Miami Open with a stomach virus,” said Federer.
“I feel bad for the tournament and the fans as I have rarely ever had to withdraw at such short notice.
“I have not felt great for a few days and unfortunately it got worse in the last 24 hours.
“I was really excited to have my comeback in Miami but I am in no condition to play. I tried to warm up this morning but it was clear that I could not compete.”
Tournament director Adam Barrett said: “We were very excited to have Roger return to Miami this year and hope he feels better soon.
“Roger is a true legend of the game and has a huge following here in South Florida. We look forward to seeing him here next year.”
MORE: The latest football news
MORE: The latest tennis news
BIOGRAPHY: Cesc Fabregas