A Makarov is not really supposed to do that. While it’s not the end of the world if it happens, if it happens consistently it probably points to some issues or wear on the parts.
Generally what happens is that inserting the mag causes the slide stop to bounce and it releases the slide forward. You can run into problems if the slide starts moving before its able to cleanly pick up the round from the magazine, resulting in either the slide going home on an empty chamber or potentially the slide picking up the round but having a misfeed and jamming the gun. I’ve never seen the last one, but I have seen a gun where the slide went home on an empty chamber.
I’d take a close look at the engagement between the slide lock and the slide, and potentially replace the slide lock.