The thing is, not only do iPhones retain value well, they have a longer service life by default.
Right now the iPhone 5s (released mid-2013) is slated to be supported at least through 2019 with iOS 12. (and Apple is focusing on older model performance this time too) Samsung flagships get two-three years of sporadic updates tops. (with random, rare exceptions)
The Galaxy S4 just can't compare to that. For $170-ish I got an iPhone 6s (2015) for my sister and we can expect it to see updates through 2020 or 2021 depending, maybe more. (and Apple hasn't pulled the rug out unexpectedly like many Android OEMs) Performance is still great a couple, almost three years in too.
Sure, you can throw on a custom ROM but you have to make sure you have a non-carrier model, have to verify what chip (Exynos, Snapdragon...) and read a bunch before going about the procedure. And on top of that, once a custom ROM enters the scene, many apps will complain/not function since the bootloader has been unlocked/phone has been rooted (see: SafetyNet) which as a whole adds another layer of headache.
Also iPhones have parts available and most shops can deal with them. Samsung phones, less so especially with the glue-heavy construction of recent Galaxy S's.