From the UESP wiki, "Skyrim: Soul Gems" article (emphasis mine):
Occasionally, dropping a soul gem you filled yourself onto the ground will cause it to lose its charge without breaking. This allows
you to clear out an unwanted soul from a soul gem (for example, if you
put a petty soul into a grand soul gem) without losing the soul gem
Filled soul gems can lose their souls when placed into a container, such as a bedside table for example, if you take them back out of the
container and put them back into your inventory. This can usually only
happen if you have empty soul gems of the same size and value in your
possession already. This is possibly because filled gems can get mixed
back in with your empty ones due to some sort of bug. This usually
occurs with Common, Lesser and Petty soul gems.
However, this bug/feature is partially fixed by the
Unofficial Skyrim Patch (USKP) (original/Legendary Edition - PC) / (Special Edition - PC) / (PS4/PS5) / (Xbox One / Xbox Series X/S). Related patch note (v1.0 - 2012-04-07):
Completely filled Petty, Lesser, Common, and Greater Soul Gems will no longer empty when dropped or put in a container (partially filled Lesser, Common, and Greater Soul Gems will still empty and this is by design so that they may be reused if incompletely filled).
You can install the Acquisitive Soul Gems Multithreaded mod (original/Legendary Edition - PC) / (Special Edition - PC) / (Xbox One / Xbox Series X/S)) to avoid Soul Gems from being "wasted" when the game puts in a small soul in a larger gem. It makes the souls "fit" to a proper-sized gem in your inventory:
...you will only trap souls into gems of exactly the right size. For example, if the only empty gems you possess are grand gems and you trap a creature with a common soul, when that creature dies the soul will escape rather than fill your grand gem with a common soul (wasting it, some would say). Same for, say, trying to trap a petty soul with only lesser gems available to it, etc. You will never "partially fill" a gem again. This also in effect fixes black soul gems and the black star so that they only trap the black souls of humans and elves, which is what the game lore says they should do. Finally, an exception to all this exists for Azura's Star, so you can continue to partially fill it and use it to charge weapons, etc.