well without driving the car but based upon your description, I woudl say your 5th gear syncronizer is bad. What shoudl you do? Well you have three options; 1) get it replaced; 2) keep your hand on your shifter every time you press in the clutch; 3) put up with the annoyance of this happening - which will only get worse.
There is some sage wisdom in Surfer18's post. It's a hassle, but as long as you have 1-4 and Reverse, you can get from Point A to Point B never having to use 5th gear. So, think about other stuff you might do to the car with the Transmission removed, such as new clutch, etc. Your tranny is optimized for 5 gears, but unless you start having trouble with other gears, you should be able to drive it virtually indefinitely with just the 4 gears.
PS -- when you have to "hold" it to keep it in 5th, you are just accelerating the demise of your 5th gear. Quit using it all together until you get it fixed.
The splines on the gear and slider are slightly "back cut" so that once they are engaged the torque will tend to hold them engaged. If it is popping out of 5th consitantly then the 5th gear slider and 5th gear should be replaced. Unless some thing else is interfering with the shifter preventing you from fully engaging 5th. The synchro rings in no way hold the gear engaged, all they are is a brake mechanism so that when you shift, the gear is spinning at the same rpm as the slidder which prevents grinding into gear.
I once had a mechanic tell me that if it ever pops out of fifth, it is very very bad, he said get it fixed. His story went something like he had a son who was driving back to adelaide from bordertown when it poped out of fifth, but he kept driving, saying the other four gears worked fine. When he got back to adelaide the gearbox was poochewed. Don't know how reliable this story is, but he seemed to know what was going on. So i say fix it now. Nobody likes a poochewed gearbox.
Graham is right--5th gear slider bad or retainer n
When the retainer nut holding the stack of gears gets loose, then 5th slides out a bit and can "pop" out. You need to remove the tranny and have that nut tightened and staked (so it won't back out again). If the gear has been damaged, it'll need replacing.
It's fairly common for this nut to loosen and 5th to start poping out.
You didn't say what year car this was in. If your Z is a first Gen (70-78), and you are importing a 5 speed from another year, it is vital that you buy the correct shiter lever.
A four speed shifter and a 5 speed shifter are very different.
The distance from the pivot to the shift engagment is much shorter on a five speed. A four speed lever does not engage properly. Many have been able to get them to work, but it just doesn't work as well as the five speed shifter.
Also, if you imported the shift lever from the 5 speed tranny, and it came from a 2nd gen ZX, the lever is not shaped correctly, and can interfere with the console. This can prevent proper engagement of 5th, letting it pop out easily. Some have heated and bent the ZX shifter to get it to work, but the lever is much shorter.
The best solution all around is to pony up the cash and get a proper 1978 5 speed shift lever. May not be your problem, but is a likely suspect.