Courtois has just recovered from an injury and Ancelotti knows that if he gets injured again, he will need a good long-term goalkeeper. Lunin made the most of the opportunity he got last year. This has also brought him a new contract this year. He has also proven to everyone that he has the potential to be a long-term Real Madrid goalkeeper.
To become Real Madrid's main goalkeeper I think it will be quite difficult but as a substitute Lunin has proven that he is quite good last season and even Lunin can be expected to do more things that are needed, so the decision to extend Lunin's contract is a reasonable thing.
Courtois is still Real Madrid's main goalkeeper, even though he has just recovered from injury he can still show his best performance without any problems.
In a team, two goalkeepers who have adequate abilities are really needed so that if one of them is injured, there will be no problems as well as when rotating players when the schedule is tight, and so far Real Madrid's goalkeepers have everything for both of their goalkeepers, so it will be quite safe.