I have the exact same problem:
I have an M2 Max 14" MacBook Pro, 64 GB RAM, 38 core GPU, 2 TB SSD. Shipped with macOS 13, but now I'm on Sonoma 14.1.2. Same issue. After a few hours of use or after sleep, Safari will randomly get "stuck" loading pages. Every other thing on this Mac seems unaffected. Firefox can load websites. iMessage works. Just Safari "hangs" for a few minutes or maybe half an hour and then randomly works again.
And also... other device in the same wi-fi works fine. There's a 2019 Mac Pro, a first-gen 13" iPad Pro, an 10" iPad Pro M1, a iPhone 11 Pro, an iPhone 12 mini, a iMac Pro a 16" M1 Pro MacBook Pro and a 2020 13" MacBook Pro... Every one of those devices never had this issue with Safari that the M2 Max has.
I talked to apple support too, there's a bunch of things we've tried. Restarting fixes it but it's not great UX to reboot multiple times a day. We tried safe mode and disabling all login items. Same issue. Now we're trying a different user account. I don't think this or re-installing the OS will help either since this problem occurred since I got this machine new with a fresh OS. However, the user account issue let me to something else...
Now here's the fun part for folks here that still have this issue:
Could you try to make a test user account and, when the issue occurs in your main user, switch to the test user?
For me, that also locks up and the login screen loads forever (over 10 minutes until I force-reset the computer).