Surely by that logic we'll need to spend £40m to replace him in two years anyway?
Therefore the options are to sell him now for say £25m and replace him with a younger, potentally better player (on half the wages) for £40m; or we release him in two years and still need to invest the same £40m; having also paid £20m in wages.
In this scenario the cost of keeping Maguire over the next two years and then replacing him will be £60m (£40m for a replacement and £20m for his wages). The cost of replacing him over the next 2 years would be £25m (his transfer fee + £15m; plus £10m in wages).
It's far, far more expensive over the next two years to keep Maguire than to sell him now, even if the player we replace him with is more expensive.