Perhaps surprisingly, there are not separate compartments inside a tube of striped toothpaste. To get them in the tube in the first place, the different coloured pastes are merged into a divided nozzle, which keeps the colours separate while dispensing them evenly into the tube from the bottom via a funnelling machine. If you were to cut open a tube of stripy toothpaste, you’d see that the stripes are thicker inside.
It’s only when you squeeze the tube that they become thinner as they flow out the nozzle. The reason they flow at the same speed and consistency is down to the scientific study of the flow of matter. In scientific terms, the stripes all have the same rheology. This means that they keep the same thickness and flow in the same way under different pressures, so they keep their positions and remain as stripes in the paste.