Bayern Munich and France defender Lucas Hernandez has been handed a six-month prison term by a Spanish court for breaking a restraining order in 2017.