Can I learn the course material for the first time while I'm teaching it?
. . . the first time I was in a statistics course, I was there to teach it. - John Tukey
In my experience, it's definitely better to learn about it beforehand. If you are really pressed for time, then start reading the textbook or course material from the back, because you really need to know the direction in which the course is going before you teach the material.
Too many times, I have done the opposite and tried to learn the subject at the same time as teaching it. This is really fun and certainly helps you to see things from the perspective of the students, but is not ideal from a pedagogical point of view, as you are too likely to be blindsided by something. The same goes for courses which are part of a series. For example, I once taught a linear algebra class and left out determinants because we were running out of time and we didn't "need" them for the exam. Next term, I got an irate email from the instructor of Linear Algebra 2...
The best possible prepartion for teaching the course in X is having taught it before.
TL;DR: You owe your students to familiarize yourself well enough with the subject matter before teaching it.
Should I have full understanding of the subject before I teach them or can I learn about the topics before I go to the class and then teach them?
While it is usually not impossible to teach a subject as you study it yourself, or immediately after you've done so - it is highly inappropriate, ethically, both as an academic, and in terms of pedagogic effectiveness:
- You are risking passing weaknesses in your understanding after an initial/brief study on to your students.
- You will not be able to provide your students with the perspective of someone who has dealt with the material in more than one context.
- You are likely not to be able to answer some of the students' questions about the subject matter.
- You will likely not be able to plan for getting finer points, ones which are more difficult to understand, over to the students - you will be expending most of your efforts in merely remembering what you've just learned.
et cetera. So - don't slack off.
A real scholar is a lifelong student.
But you should know the material that you are teaching sufficiently broad (like you won't be caught ignorant of some relevant factoids) and sufficiently deep (like you won't be caught not understanding some relevant factoid) that your authority of the subject is not questioned and you won't be embarrassed. (And the students will not think they're getting screwed with regard to their tuition dollar.)