It's probably contractually standard. Compare Hugh Edwards in a similar position.
Assume a normal person taking the role of ambassador. For most people, that is a disruptive life change - involving moving country, having an official residence in some cases, giving up an existing job. The contract will need to be able to be terminated by the employer (the government) because anything could happen - an election, a war and recall or just on a whim. The employed person (the ambassador) would need some financial protection and cushion because they will be losing their job, their home and livelihood in one go plus have relocation costs.
If it's contractual, then the person is legally entitled to it. As it stands, Mandelson hasn't been convicted of anything and at the point he was sacked (before the later government info emails came to light) it was just a reputational problem so there wouldn't have been a basis to refuse to pay it.
In practical terms, the government could have refused to pay it but would have been gambling on Mandelson choosing not to sue. If he has a contractual entitlement, then he would win so that would be a waste of more tax payers money.
The other possibility is that he may have been contractually entitled to more and the ultimate sum was as the result of a legal negotiation to get him to go. That is also fairly standard in situations where the employer wants a person out fast, they know they are on weak ground but the law requires a process to be followed - it is sometimes a trade off with a non disclosure agreement and a lump sum that gets the person out quickly and avoids litigation. That's more likely in a non-government situation.
He won't repay anything paid though - why would he? Just like Hugh Edwards. If you are legally entitled to some money, it's been paid to you and you are going to have big problems getting any other work, you will cling on to every penny.