Does this happen to you when waking your computer from sleep?
It's not just about sleep... though sleep does seem to be a catalyst some of the time.
For me it has done it more than once while actively transferring files from internal drive to external. Obviously, neither end can be asleep during a file transfer.
The sleep thing leads to recommendations for apps to keep the connection awake 24/7 and similar but that solution is simply going to wear out the external faster than the way that historically works... which lets a Mac sleep, drive sleeps, Mac wakes, drive wakes and no "unexpected ejections."
I've pounded through EVERYTHING trying to get a near mission critical enclosure working fine with my "latest & greatest" Mac Studio Ultra. Nothing works. However, pull in a pre-Big Sur Mac and hook the same cable to it (all else renaming the same) and that external is perfectly stable again.
I'm convinced we need Apple to fix this problem in macOS. The user solution until then is to buy a different enclosure and try that one. Be sure you can return it if it "unexpectedly ejects" too. Eventually you find one that will stay connected. It's too bad it is now this way instead of "just works" but this is the way it is.
Some enclosures will work fine and others won't. Age (of enclosure) is not a factor as I pulled out ancient ones when I was testing to try to figure out a solution other than macOS. It's not a brand thing as the replacement one that works for me is the same brand as the one that is now problematic on (since Big Sur) Macs.
Users should try the easier stuff they can try such as swapping a cable, trying a different port, bypassing a hub if they are using one, etc. But odds seem very high, this is a bug(s) in macOS and only Apple can mostly resolve this issue so the U in USB means what it should again.
Again, anyone doubting cable or hub or enclsoure or firmware, etc... just hook the one ejecting to an old Mac or a PC and it will probably be stable again. That should tell us all something. If not, re-read posts of those who have downgraded macOS back to something
before Big Sur and the problematic drive resumes a stable connection. If that one variable is the only variable that changes, the problem seems centered in one thing.