The evolutionary purpose of rubber, and the reason why it has appeared independently in plants as diverse as trees, guayule and dandelions, is that it gums up the mouthparts of herbivorous insects.
This particular ant, Pseudomyrmex ferruginea, is a hard-biting acacia defender. It protects the plant from other insects, bigger animals and well-meaning trail guides.