When the carbonated root beer comes into contact with the ice cream, carbon dioxide bubbles release. Likewise, the soda frees air bubbles trapped in the ice cream. What's more, the fat in the ice cream coats these bubbles. Therefore, creating the huge heads of foam you see on root beer floats.
Root beer was originally made partially with sassafras root bark (and sarsaparilla, etc) which naturally foamed. Carbonated beverages form bubbles - in seltzer water the bubbles dissipate quickly. When flavoring ingredients are added, the bubbles frequently form a longer lasting foam.