That's not quite true - the problem is that as an employer you owe a duty of care to your employee and a reference forms part of that duty of care. So if you breach that duty in providing a reference, you could be sued by the employee. So what you write in the reference has to be demonstrably fair (you have a duty to take reasonable care to ensure it is true, accurate and fair and that it is not misleading – a duty that is owed to both the employee and to the new employer). For negatives like the ones above, it may be very difficult to prove they are fair comments and if the employee fails to get a job because what you breached that duty, this can give the employee a cause of action.
That means it is invariably safer to give no reference at all, which is a shame, but the idea is to protect the employee from vindictive employers who do not want the employee to leave or have a grudge.
It's not "illegal" in the sense of being a criminal offence though (they could also sue you for defamation too). You are perfectly at liberty to write a reference like this, but you may find you have to cough up in order to do so.
And I think it is amusing