The match will mark new head coach Erik ten Hag's first home fixture and will come one week before the start of the new Premier League season.
Man United will start their pre-season with a game against Liverpool in Bangkok on July 12 before flying to Australia to take on A-League side Melbourne Victory on July 15 ahead of a clash with fellow Premier League side Crystal Palace on July 19, with both matches taking place in Melbourne.
The 20-time English champions will then be in Perth to tackle Aston Villa at the Optus Stadium on July 23 before facing Spanish giants Atletico Madrid on July 30, one day before the game against Rayo.
As a result, Ten Hag will be heavily rotating his squad for the matches on the Saturday and Sunday, as he looks to get his players up to speed for the new campaign.
"Pre-season is all about preparation and this is a great opportunity for those squad members who may not have featured in some of our earlier Tour and pre-season matches to get valuable minutes on the pitch - and where better to do this than Old Trafford?" Man United football director John Murtough told the club's official website.
"This will be the new manager's first match at Old Trafford, and I am sure the fans will provide him with a warm welcome."
Ten Hag revealed last month that Man United will officially begin pre-season training on June 27, although those involved for their countries this month will not link up with the team until a later date.
The club's new head coach was in the stands for their final match of the 2021-22 Premier League campaign, which ended in a 1-0 defeat to Crystal Palace.
Last season, the Red Devils finished sixth in the Premier League, reached the fourth round of the FA Cup, third round of the EFL Cup and last-16 stage of the Champions League.
"We are delighted to be able to offer fans the opportunity to share in the experience of Erik Ten Hag's first match in the dugout at Old Trafford," added Man United's chief operating officer Collette Roche.
"As well as the chance to see some of the club's up-and-coming stars, fans purchasing tickets for this match will also be contributing towards a fantastic cause, with the club donating 10% of profits from the game to Manchester United Foundation and its work within the community."
Rayo, who finished 12th in La Liga last season, have former Red Devils players Bebe and Radamel Falcao in their first-team squad.
Man United will not be in the Champions League next term, but they qualified for the group stage of the Europa League despite a disappointing end to the 2021-22 campaign.
Ten Hag will hope to have some new faces in his squad for the team's pre-season opener next month, with Barcelona's Frenkie de Jong, Ajax duo Jurrien Timber and Antony, and Villarreal's Pau Torres among those being linked with switches to Old Trafford.