If you choose to do an MD/PhD program, you do your pre-clinical curriculum and then go do your PhD research (+courses if you need to take any) full-time for around 4 years. At the end of that time, you will write and defend your dissertation, which gives you the PhD. Then you finish out your clinical years and earn your MD.
There are people like me who do PhD and MD separately and already have PhDs going into medical school as a result of career change. There are people who decide to transfer into the PhD program during medical school during which they will follow a path very similar to the one outlined above. And there are yet more people who graduate with an MD and pursue a PhD afterwards, separately.