Great question!
In the "olden days" the team that won US Nationals became the US National Team.
Now, there is a ranking procedure that all qualified athletes compete in individually to earn a ranking and a spot on the team.
First they compete in two rounds of technical element competitions and get a ranking. The top 30-50 of them (depending on the year's competitions) will continue on to the routine phases.
They all learn the same routine, and swim it twice individually for a score. Then the National Team Director puts them into groups of two, three, or four in order to help the judges compare them more directly. After two group swims, and the compilation of all the scores, they are ranked.
The top 10 or 12, depending on the major international competition they will be going to, make up the US National Team.
You're right about the team chemistry too, though. For the Olympics, the team trials are much farther in advance. For example, the 2008 US Olympic Team was chosen in January 2007 to give the team the maximum amount of time to train together.
Attachment