Is it okay to send a thank-you-for-teaching to a professor who taught a course a few semesters ago?
Yes, it is entirely appropriate and will be appreciated. Let the person know a bit about your current activities - especially successes.
Even better, if it weren't for the pandemic, would be to pay them an in-person visit during office hours. Too few people get a chance to thank their important mentors, I'm afraid.