The gun is doing what it is supposed to do.
If an empty magazine is in place the follower will lift the slide lock upward and the arresting notch of the slide will catch it.
If the magazine is not in place there is nothing to push the slide lock upward unless you manually do it.