It depends on whether you take the more comfortable, air-conditioned, Campania Express (http://www.napoliunplugged.com/campania-express-tourist-train-to-herculaneum-pompeii-and-sorrento), which does have toilets; or the normal, more frequent, Circumvesuviana, which doesn't - but the journey only takes about 30 minutes ...