Should a professor write a Letter of Recommendation if he does not remember the student but does remember that the essay the student submitted was excellent?
It's not clear if the question is being asked from the standpoint of a student requesting an LOR or from that of an instructor who's received a request.
If the question is from a student, the answer is, there is no "should". An instructor is free to decide whether or not to write an LOR based on whatever reasons they like. They are under no obligation to write an LOR just because they remember the student or a particular submission. In practical terms, most instructors will decline if they don't think they can write an LOR that will be helpful to the student, either because they don't know the student or their work well enough or because they just weren't that good. Obviously, there's no point to writing a poor reference so most instructors just won't do it, no matter how much a student might think they "should".
If the question is from an instructor, the answer is, there is still no "should". You are free to decide on your own whether you think that one submission plus whatever other evidence you have is enough to support a helpful LOR. You might, e.g., review the student's grades in your class and their other submissions, e.g., if they were captured in Canvas or a similar online system, you can ask the student to provide a copy of their transcript and an essay on their objectives and you can ask to meet with them to help you decide whether and what to write. If you teach at an institution with large lecture classes (e.g., I have 250 students in one of mine), it's inevitable that you won't get to know even some of your best students but you may still be able to review their work, describe what they did and what that means for their potential, in which case it may be perfectly appropriate to write the LOR.