"Sharapova requested an invitation to play in the tournament and after considering it, we decided to give her a wildcard," said Manolo Santana, the tournament director, in a statement.
"Maria is one of the best players of the last 15 years and also a past winner of our tournament. In Madrid she always plays well and I'm sure she will come back to the courts highly motivated and hoping to do well in her first tournaments."
Sharapova, 29, last won the event in 2014, beating Simona Halep, 1-6 6-2 6-3, in the final.
"Sharapova is one of those players that all tennis fans want to see," added Mutua Madrid Open CEO and President Gerard Tsobanian. "Her presence in the Caja Mágica is great news for the tournament, for the fans and also for the city of Madrid."
The Russian makes her return to the tour in Stuttgart in April following her positive test for a banned substance in 2016.