Yes, the reason why is that the mag in the gun has an "orientation" just as you can orient the mag in the inventory to be horizontal or vertical.
When you reload, the system isn't sophisticated enough to rotate one of the mags to make it fit.
Because there is no vertical 1x4 of free space in your inventory for the mag in your M4, the mag will drop to the ground.
It isn't a bug, it's the feature, and it is possibly intended, with a concious decision.
A solution that could work, but may have a negative effect on the community:
Auto sorting of inventory slots.
If there are enough free slots, but they are not contiguous, then the items will be automatically "shoved" in the least computationally intensive way to create space, mangling any organizing. The mag will be oriented whichever way is simplest to calculate.
Why this may be bad for the game:
Some players take pride in organizing their inventory, and have grown a skill in quickly identifying what is useful, and what to drop in order to make room for an item. This system would circumvent that in some situations when the free slots are very scarce, and players play "tetris" to store items.
Although, in terms of realism it does make sense that you could "stuff" something into a container, however it fits, whatever it shifts around.