It appears to be experience -- highly skilled pianists have played similar passages for pretty much any sheet music you could give them, and select fingerings from experience. This breaks down for music that's deliberately difficult to finger, or has usual repetition (think Ravel's Ondine, or Islamey).
Experience, sight-reading skill, and experimentation. My piano teacher used to play passages that needed fingering at full speed several times with different fingerings to find one that would work for me.