Now to the problem at hand. With no mag in the pistol if you invert the gun and rack the slide does the slide stop drop and lock the slide? If so problem with detent (needs more depth of detent notch, or plunger tube, spring not providing enough pressure) look for issue's.
If it does not fall and lock the slide when racked upside down then remove the slide, load a dummy round (preferred) into the magazine, leave the slide off, but put the slide lock back into the lower frame and insert the mag with the round. Take notice if the round rubs the end of the slide lock lever that protrudes into the mag well . It should clear the round but still stick out far enough that the portion of the mag follower which activates the slide lock still works. If it rubs the round you need to remove just enough material from the contact end to clear the round.
Most of the time its this later issue.
If it was occurring at random rounds I would say operator error (thumb bump) but since on last round only I would be looking at the mag follower relationship to the lever interface.
Hope this helps