Is it? Android already disables sideloading by default, requires each source to ask for permission, and prompts the user before each install. How does Samsung's additional setting improve security?
I think the Pixel Fold might be the best option for a foldable phone, because (just like all other Pixels) you can flash it with a private, secure, open-source ROM like GrapheneOS.
If you mean the S24, the equivalent from Sony would be the Xperia 5 V. Has audio jack and sd card compared to the S24, Sony batteries last 2 days even after several years of use thanks to excellent optimization and battery care, there's almost zero bloat. On the downside it will only get 2 years of upgrades (until the end of 2025). Also you can't unlock the bootloader on US models if that's something you care about.