What causes a filesystem to get corrupted?

A file system is corrupted when its internal structures are inconsistent. There are essentially two sources that can cause this: hardware and software.

Most likely these days, this is due to a hardware failure. If a sector starts malfunctioning the data it returns can differ from what was written which can corrupt the file system. If your SSD is fairly old, it is probably time to replace it but you can use a tool such as smartctl to monitor its error rate which can indicate eminent failure. SSDs in particular can only be written to so many times per block, so after a few years they will start returning errors. Manufacturers overprovision and save extra blocks to replace ones that got worn out to extend SSD lifespan but eventually those run out too.

It is possible a software error caused a corruption but it is quite rare these days since filesystems have been in use for a long time and so nearly all bugs have been fixed. What it still happen though is a serious crash or loss of power that can result in file-system corruption when the unexpected shutdown occurs while the filesystem is being modified. Some filesystems have journalling to help limit this type of issue but it can still happen.