The easiest way to think about this is that the strings will put a given amount of energy into the top (based on gauge, scale length, string construction, etc.). That top can release the energy quickly (more volume, less sustain), or more gradually (lower volume, longer sustain). The rate at which the guitar releases the energy has a ton of factors affecting it (so many that I will not list them all, and I don't know that I would get them all anyway). Suffice it to say that this is a big part of what the guitar design is about.
The type of music to be played also determines the ideal volume/sustain is desriable. Some music (think a lot of very rapidly played fingerstyle notes, or gypsy jazz, some types of bluegrass) would best be served by a higher volume guitar (and by extension, shorter sustain) type of guitar, so that the notes die off quicker because there are a lot of notes coming in a short period of time. Folk music, or more contemplative music, may be best played on a lower volume, longer sustain guitar.