Check all the external parts and in particular, that there's nothing resting on the gearstick when in 2nd (eg, carpet etc) and that the shifter body mounts are also good.
If that checks out, then usually (and commonly) it's a worn selector fork in the gearbox.
Don't let it do it too many times, in fact avoid it slipping out of gear all together as on top of the selector fork, you'll also be up for a 2nd gear.
I'd actually recommend, if the box has to come out and have the fork changed, to overhaul the whole box, including the diff. This is usually a selector fork for 1st / 2nd (the one for 3rd / 4th is usually OK), Bearings, Layshaft, Baulk Rings & Springs as well as just about everything in the diff. I suggest this because more often than not, by the time the gearbox is worn to the point of slipping out of gears, the rest of it isn't too far behind.