The way most people are answering is based on ethical reasoning (which I don't disagree with), but some of the OP's follow up comments / questions make me wonder if OP is contemplating whether doing the "nice" thing (which supposedly have negative short-to-medium term consequences) might actually have longer term consequences, or not. I think the answer is: failure to write the LoR in this case is actually a bad idea for the professor.
By refusing to write a LoR, the professor in question believes that they are more likely to keep a potentially useful grad student / employee; writing the LoR makes this less likely. So, doing the thing that helps the student achieve their goals seems to hamper the professor's. However, I'll argue something much different: the pragmatism of niceness (or, at least, perceived niceness), which some of the answers (Zero's; Sandra's third point; Lecter's third para; and Peteris') have alluded to, but I think is worth stating straight out.
If we re-examine some of the assumptions in the professor's argument (or, at least the one I'm imposing on them), there's the notion that the lack of LoR makes it significantly harder / less likely for the student to move on.
- Having a LoR from a well known professor with whom you have worked is nice, but not the be-all-and-end-all. In the post linked to by the OP, answerers were arguing the the student in question should go get other LoRs. So, the professor's refusal to write one is not a deal breaker for the student's efforts to move on.
- Also, the professor has assumed that failing to get a LoR will not impact the effort the student puts into leaving. There are lots of folks (myself included) that would make it a TOP priority to ditch a boss that treats me like that. Lastly, even if the student doesn't leave, the professor has not (apparently) thought about how failing to write a LoR will impact the student's desire to put time and effort into the job.*
- Plus, let's be honest; the professor can try to attract another student, right? The loss of this one is probably only a temporary set back in that the professor needs to start the process to get another student.
So, I question how effective this lack of a LoR is for the professor's future benefit (i.e. keeping a well-motivated student to work in the lab). Then there are the potential negative consequences for the professor.
If word gets out about this attempted sabotage, the info would have to get to potential applicants, before they would choose not to apply into this program. But, this can happen; it could negatively impact the climate of rest of the lab (who, if annoyed enough by this or other bad actions, could tell potential new students). Additionally, the professor could develop a bad reputation among colleagues, who will be less likely to send new students to him. (Let alone any other consequences, such as de-prioritizing collaborating with the professor, if the reputation gets worse.)
So, I will say that it is actually in the professor's best interest to write the LoR. The benefits of trying to keep the student are probably less than the professor thinks, and the negative consequences are probably much worse.
*Just to cut off any arguments about how no-one owes a LoR to anyone else: Wanting someone to stay and work for you, but being unwilling to write a LoR for a similar position is a major red flag to me; it smacks of the employer/professor failing to see the employee/student as anything other than a means to an end for the employer/professor. It would be different if the employer was getting ready to fire the employee, of course.