How does this baby rattle work? Here's a gif showing how the balls move when I move the rattle. The circular tube hangs vertically, with the balls on the bottom. There are more images in the bottom.


*

*The balls roll freely inside the tube

*The inner diameter of the tube is larger than the diameter of the balls

*I have tried taking an external magnet close to it, but the balls aren't affected by it.

What makes these balls repel each other?

As you can see from the image below, the diameter of the balls is smaller than the inner diameter of the tube (it is identical if I flip it).


Edit: Here's a gif showing what happens if I leave it be for a while, then shake it. Looks like knzhou is right.
 A: There aren't that many repulsive forces out there which could be at play:


*

*magnetism

*electrostatic forces

*compressed material (solid, fluid or gas) pushing bodies apart


Magnetism would have worked if the bodies would not be able to rotate, or if we could produce magnetic monopoles.
Compressed springs are extremely hard to make completely invisible. Liquid or gas could be unnoticeable, but like you said, those balls don't seal the tube and cannot prevent the gas from escaping.
Which leaves you with pretty much the only option: electrostatic forces.
A: As you said, it's probably not magnetism if the balls are free to rotate; there is no reason they wouldn't just flip over and stick together, north to south. You can test this by buying some of those toy magnetic balls. The repulsive configurations are highly unstable and turn attractive with the slightest touch.
I'm going to go out on a limb and say it's static electricity; the balls are picking up charge by rubbing against the plastic. The electrons will always go to whichever material 'pulls' them harder (according to the triboelectric series), so the balls all get the same charge and hence repel. 
I don't have a baby rattle with me but here are some ways you could test it:


*

*If you don't move the rattle for a while, the balls should come together as the static dissipates

*The effect should come back once you shake the rattle a couple times

*The effect should be smaller on humid days where static dissipates faster

*Another statically charged object should attract/repel the balls, e.g. a balloon rubbed on hair. (The plastic ring will not block this effect, since it's an insulator.)

A: The balls are what's called electrets.  They retain a static electric charge that is uniform within them.  This is the same effect makes plastic cling wrap work.  You can look up "electret" on the web to find out more.
