He was expensive to keep and expensive to dispose of. It cost Real Madrid 8 million euros a year to keep Ancelotti as their manager and it has cost the 4 million Euros to relieve him of those duties.
Ancelotti was fired for failing to win a single trophy in 2015 there and Florentino Perez against the wishes of some players and almost all the Real Madrid fans decided that it was time for a change. Ancelotti however has a clause in his contract which states that if Real Madrid terminated his contract before it was over, they would have to pay him half of his yearly wages which amounted to 4 million euros.
Ancelotti is set to go on a sabbatical and while people think it is a bad thing to lose your job, Ancelotti can at least pick up 4 million positives from losing this one.