It is another unfortunate blow for the former world number one, who defeated Denis Shapovalov on Tuesday for one of the best wins of his comeback and had been looking forward to a first clash with his long-time rival for more than five years.
Murray reversed his decision to skip the clay-court season by taking a wild card for Madrid and showed impressive form, defeating Dominic Thiem in the first round and then 14th seed Shapovalov.
Provided he recovers in time, Murray must now decide whether to play in qualifying for next week's Italian Open, while the French Open is still potentially on the table despite the Scot previously saying he would not play and would instead concentrate on preparing for the grass-court season.
Murray helped set British tennis history in the Spanish capital, joining Dan Evans and Cameron Norrie in making it the first time three players have reached at least the third round at the same Masters event on clay.
Evans will take on sixth seed Andrey Rublev on Thursday, while Norrie meets Spanish star Carlos Alcaraz.