The mechanism of the Mannich reaction starts with the formation of an iminium ion from the amine and the formaldehyde.
The compound with the carbonyl functional group (in this case a ketone) can tautomerize to the enol form, after which it can attack the iminium ion.