Many institutions include in their definitions of plagiarism something like:
submitting a paper as original work in one course when the paper has already
received credit in another course (unless prearranged with the professor).
(The above is from my own institution's Honor Code, as stated in the student handbook.) If you were at my institution, what you're proposing wouldn't violate the letter of the honor code since the work wasn't graded in another course. Your own institution probably has an honor code or a policy on "academic integrity"; it may or may not have similar language. As far as the "legality" of what you're proposing goes, your answer is probably in there somewhere.
That said, you probably still sense that your instructor might not look kindly on this—otherwise you wouldn't be here asking the question. If you were my student and you handed in work that you had written well before you even took my course, I would be somewhat disappointed. As @Kerkyra alludes to in their answer, the reason I assign essays & written work is to make you think about a subject in the context of my class, as part of the process of learning the course material. By presenting me with work whose preparation was completely separate from my course, you're depriving yourself of this opportunity to make deeper connections and understand the subject even better than you did before.
However, there could be other professors out there whose main goal in assigning a paper is simply to allow the student to demonstrate mastery of a particular subject; such a professor would probably be fine with you submitting your older work. Other professors might have different pedagogical reasons to reject the idea. So it probably boils down to the following: ask your professor whether this is acceptable. Depending on their pedagogical priorities in giving this assignment, several things might happen. They might say it's fine; they might say "I'd like you to substantially revise/rewrite it" (as suggested by @Kerkyra); they might say "actually, this paper wouldn't satisfying the requirements of this assignment, so you'll need to pick another topic"; they might say "I want everyone in the class to be writing about something they don't already know about"; or something else entirely. Ultimately, if you want to do something unusual for an assignment, it's better to ask permission of your professor than it is to risk a messy and protracted debate over its acceptability after the fact, when your grade is on the line.