How is it safe to buy a refurbished iPhone like from Amazon since the data from the previous owner could still be on the device and accessed by you or because the previous owner's data could become mixed in with your data or accounts, even if the device is factory reset?
Well…the iPhone would first have to be unencrypted. Or you'd need the key to access the encryption.
Then you'd need tools to execute data recovery. This is after establishing that the device running the data recovery software can connect and talk to the iPhone.
But…
Apple devices are all encrypted. And the key to the encryption is discarded whenever the device is restored. So, even if you knew data was there and could run data recovery - you'd get gibberish, because you don't have the data encryption key. Nobody has it.
So, at this point, your question goes right out the window.