What's the best way to connect two separate generators to a well pump?
Many generators (especially those for permanent installation) have optional automatic transfer switch assemblies.  If the backup generator is permanently installed, then I'd recommend buying its recommended transfer switch.  Wire it per its instructions.

If you're going to build your own transfer switch, then make sure that it is "break before make" or has some sort of interlock to prevent both generators from connecting to the load at the same time.  Mains should also be isolated from either generator if mains is present on site.