Why is jazz mostly written in keys with flats?
There’s lots of great answers to the question here, but I would like to add that, it’s the same reason that there are a lot of Rock songs in sharp keys! Why? Because it’s about who is composing the songs. Guitar players generally write rock music and they like to use keys where they have more open strings. It’s simply easier to play with open strings so that’s what they gravitate to. G, E and A which are probably the most common rock keys.
Similarly, the reason jazz is mostly written with flats is because jazz often uses horns and it’s easier to play a horn in flat keys because they are transposing instruments (pitched in Bb and Eb). So, as an example, if a song is written in Concert F (one of the most popular keys), then Bb instruments (like trumpet and tenor sax) are playing in the key of G, and a song in the key of Bb would put a horn in the key of C, etc. Those are easy keys to play for horn players so those are the keys that jazz writers tend to gravitate to especially if they’re writing for horns as well as the tradition of flat keys.
One of the favorite keys of guitarists is E and that puts a Bb horn player in the key of F#. Not at all a friendly key for most horn players. But, even if you’re a horn player and you are forced to play with guitar based bands you will become more adept at playing in sharp keys. There are some horn players which actually PREFER sharp keys especially for blues based songs because the blues scale adds flats to the key.