There are numerous reasons why a composer would write a work in a certain key. If the composer is writing a song for a vocalist, the key may be chosen to work well with the singer's vocal range. For songs with bowed string instruments, those usually favor keys such as C,G,D, or A. The reason being, those are the open strings on the cello and thus make it feel more natural to play. So bowed string instruments are typically more comfortable when playing in keys that have sharps. Horn instruments are typically more comfortable playing in keys that have flats.
The composer could also just like the way that playing their tune in a certain key feels. Sometimes I begin composing in a key like Eb on guitar, that I would not consider to be a very guitar friendly key, but it's because I like the sound and where it takes my melody. So sometimes, a composer might just feel a certain key.