Madrid signed the 19-year-old goalkeeper earlier this year, but he has not been involved with the main squad.
He will now join Leganes, a LaLiga side based in the outskirts of Madrid, for the coming season on loan.
Keylor Navas was Madrid's first choice keeper, and Lunin has moved further down the pecking order after the arrival of Belgium's Thibaut Courtois.
Courtois had been looking for a move to Madrid for a while, and it became a reality this summer.
Lopetegui has a tough decision on his hands with regards to goalkeepers.
As well as Navas, Lopetegui has Kiko Casila and Luca Zidane to choose from.