Eh, Madrid didn't want to get rid of him no, they were willing to offer a new contract but they just weren't willing to offer him the kind of contract that he wanted. He thought he deserved to be paid more (I agree with him on that) and he got that at United.
This isn't confirmed but there were rumours that he was upset that he wasn't appreciated enough. He was very much second fiddle to Ramos and always got blamed for mistakes that weren't solely his. Madrid media never protected him, he was often the scapegoat even though the truth is they were a very complementary pair and Varane often cleaned up his mistakes. I remember at one Champions League press conference a journalist basically asked him a question implying whether he was any good without Ramos, it's not just people talking on the Internet. After all he had done for Madrid, he was upset with all of the criticism, especially after his mistakes against City. Based on what I know of Varane personally and of Madrid, I personally think those rumours are true.
It's probably also true what was reported about him wanting a new challenge. So lots of factors for him wanting to leave and Madrid didn't value him enough to convince him to stay so had to sell him. They would have happily kept him.