If the original owner has been deleted, and it's been more than 20 days ago, it is no longer possible to transfer the course.
The Classroom API does not allow updating a permanently orphaned course.
If the deleted teacher is still listed in Recently Deleted, then you can restore the user temporarily and transfer the course.
This is why it is imperative that leaving teachers take proper care of their Classrooms before they leave. Or you do.
Alternatively, create all Classrooms centrally with a utility account, and just add teachers as co-teachers, not owners.