This can happen with any semi auto, but is pretty common with high capacity designs. If you are not slamming the mag in, (they will all do it if you slam hard enough) it indicates that the slide catch is not completely engaging into the notch in the slide.
This may be caused by the notch itself not having been cut at the correct angle (should be slightly undercut, not squared at 90 degrees); a burr or other issue with the catch; weak mag springs that fail to push the follower up far enough for complete engagement by the stop; mag springs installed incorrectly; dirt and crud; or magazine followers that are worn where the follower meets the slide catch. In extreme cases, it can also be caused by weak ammo or a dirty chamber, or insufficient lubrication, since these issues may allow the pistol to fire and function, but not quite engage the catch fully when the last round is fired.
If you decide to "fix" it yourself, remember, always work on the cheapest part. If you really believe the slide should be altered, send it back to Glock and let them do it.
Look and see if you find any of these things with your pistol and mags.