Okay update time:
Thinking that the update might have worked, I then carried on and did the rest of the updates from 5.1 up to the latest version.
It didn't work. I got an unrecoverable error message on the main gallery page.
I then restored the database back to the 5.0.3 version so I could retry.
I then updated phpBB to the latest version 2.0.19 (we were on 2.0.11) in case this was the problem.
I then retried upgrade.php and had the same errors.
Then to ascertain what the actual error was, I went into pp-inc.php and removed the "if ( $User['adminedit'] == 1 ) " from line 324 so that the error would be outputted, and this is what I got:
Content visible to verified customers only.
So at the moment, I have no idea. The main problem seems to be the weirdness of the 5.0.x to 5.1 upgrade script. If I can get to the bottom of that, I might be able to work out the rest?