This is definitely not expected behavior. Can you keep dmesg -w running in a terminal (potentially via ssh) to watch for kernel messages before the freeze happens?
Before you do that, though, to prevent potentially destructive mistakes, are you using btrfs? If so, check for data corruption before continuing to use the system, you can’t simply use a raw swap file on btrfs, you need to specially prepare it: Swapfile — BTRFS documentation
I really disrecommend using swapfiles in general, if you need more swap space just resize your partitions: