Why does magnesium bromide transfers from a carbon atom to nitrogen in piperidine?
There is no step 1 and step 2 in this reaction. Both are consecutive and second one is fast because it is an acid-base reaction:

Note that approximate $\mathrm{p}K_\mathrm{a}$ values of ring $\ce{C-H}$ and $\ce{N-H}$ are 50 and 40, respectively. Thus, as soon as Grignard reagent is formed, it exchanges relatively acidic protons of $\ce{N-H}$ fast (Remember, Grignard is also a strong base). To visualize the exchange process, I included schematic representation at the bottom of the image.