Jumping out of gear usually means it didn't fully engage.
Either the selector fork is well worn, so losing movement, or the gears have too much movement along the shaft (should be miniscule).
Selector fork wear is caused by every owner holding the gear lever much of the time, instead of the steering wheel, but modern oils and gearboxes are much less prone to this wear.
Excess play option could be caused by the nut on the end of the gear shaft, at 5th gear, coming loose. This can be checked relatively easily by removing the gearbox end cover, under the battery. Time for oil up the sleeve. If it is loose, tightening it may fix the issue, if damage is not too great. There have been a few reports of these nuts becoming loose over the last few years.
Tightening it to the correct torque is a challenge. When building a gearbox this is done on the bench, and two gears are selected together to lock the shafts. Might be possible if the selector mechanism is removed from the top if it brings the interlock mechanism with it. Might work with it in gear, both wheels on the ground and someone stood on the brake, but access then is difficult. If heaving to tighten a nut whilst under the car, ensure it is very well supported.