The player has agreed terms and passed a medical. He will be officially unveiled in the coming days and will then join up with the Sociedad squad in Germany.
Hernandez made 13 appearances in La Liga for Real Madrid last season after joining the club from rivals Atletico Madrid last summer.
He acted as backup to Marcelo but the Brazilian's consistency means that Hernandez is unlikely to overtake him in the pecking order any time soon, so he has gone on loan to get more minutes behind him.
In his absence, it is thought that academy player Sergio Reguilon will deputise for Marcelo in case of injury or suspension.
Hernandez has been capped for France at youth level and was brought to the Santiago Bernabeu by his countryman Zinedine Zidane last summer.
He had spent the previous season on loan at Alaves, where he made 32 league appearances and scored the first goal of his senior career against Athletic Bilbao.
He helped Alaves to reach their first ever Copa del Rey final in 2017, and scored a free kick in the final against Barcelona. It turned out to be in vain as Barca won 3-1.