For old phone like iPhone 5, filling random data to the device is more secure than factory reset. However, for newer iOS device, a simple factory reset is enough to protect the data.
Official tutorial: https://support.apple.com/en-us/HT201274
How to fill random data to iphone...