In what cases iOS stops screen recording on its own?
As far as I know, locking the phone (pressing the power button once shortly) will also stop recording.

Just like anything else, it requires enough free space on your iPhone to save the file. However, that doesn’t sound like the problem in your case.

There might be a chance that your iPhone 5S might not fast enough or have enough memory to record as long as your iPhone X.