If you put that ball on that machine while it wasn’t spinning, it would just roll straight down the lower sides.
The raised edges would keep it in the middle line, but it’s only controlled in one direction. By spinning it, you constantly alternate the position of the tall sides, meaning that the ball is held in the middle, never able to fall off.
Particle accelerators control particles in the same way. Magnetic or electric fields can only direct particles in one plane at a time, so to keep a beam of particles rushing down a particle accelerator in one focused stream, the current gradient must constantly oscillate. This means the particles are constantly held in place, never able to shoot off in one direction.
Here’s the same principle in action: these are tiny pollen grains being held in place by an oscillating field. Rods in the four corners of the beam establish a field that oscillates many times a second to keep the pollen trapped. If it didn’t constantly switch, the pollen would all fly off in one direction.