Some employers puts conditions on matching of 401k. Applying vesting schedule to matching amount is one of the popular way. Remember that what you contribute to 401k is your own money and vesting does not apply to it and it applies to only matching amount contributed by your employer.
So when you leave your job, your non-vested money (of matching money) will be taken away by your employer. Not only that earnings on that non-vested money is also taken away.
That's why employers use this way as retention tool.