We were at Pompeii last week.
I'm assuming since you're taking the train, you'll be riding the Circumvesuviana train from Naples to Pompeii? If so, read on-
We arrived at Pompeii around 10:00 am, a little early to meet our 11:00 am Mondo shared tour guide, ( which I recommend.) we gave our cash to the guide, who walked up and immediately purchased our tickets at a secondary gate.
There's a carnival- type atmosphere in front of the main entrance, with crowds of folks getting off the train, and food and merchandise vendors all around. The lines to tickets at the main gate didn't seem very long.
Do not listen to the folks at the train station guiding you to an upstairs office to buy tickets. They are private sellers trying to sell their tours, not Pompeii employees.
I have not read about Pompeii ever selling out; the area is huge!
Leaving Pompeii, I must warn you to be prepared for a very crowded train, very hot, standing room only. It was actually painful, after being on our feet at Pompeii for several hours. I suggest you have plenty of water, and aren't hungry . The train ran late, and because of areas with only a single track, our train was delayed as it had to wait for other trains to clear the single track areas. The afternoon train took twice as long as the morning train.
I didn't look into the Campania Express Train, from Naples, which only runs four times a day, but I would recommend that, as it's less crowded and has air conditioning.
Pompeii is amazing, but as I think you know, coming from Rome will be a long and arduous day.
Good luck!