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.