For example, if I get a lead sheet I have never seen before and it has a chord that is not in its center key, how can I easily recognize what mode or scale to play over it when improvising?
Looking at chord tones and the chords themselves is probably a better approach in this circumstance. So, if you are playing in C major, and a Gm7 chord appears, you could simply play a phrase from a Gm7 arpeggio. Or, you could stay in C major and be more careful about the notes you choose...for example, a Gm7 chord contains the notes G-Bb-D-F, three of which (G,D,F) are in the C major scale - so you could play those notes from C major, and make sure to avoid the B note in C major (which might not sound the best in this context). Or, you could play the Bb note instead of the B note in C major while the Gm7 plays. C major scale notes over the Gm7 chord also imply different tensions, for example, if you played an A note from C major, that would imply a Gm9 chord. As long as you know what you are doing, feel free to be weird...that's jazz.
I'll describe one method that can work when you're in a pinch. However, the effectiveness of this method depends on how familiar one is with the main parent scales (major, melodic minor, harmonic major, and harmonic minor). If the method I've described fails, then the sure-fire way to get an answer is simply to look it up online or in a theory book. I say that as a real suggestion: looking up the answer isn't counterproductive in the long-term, because the ultimate goal (from a performance and practice perspective) is to memorize the modes that match which each chord. The downside, obviously, is that you can't do this on a gig. So here's an imperfect but still pretty good method that often works.
Step 1: Play the Chord with Extensions
First, play the chord. Put the root on bottom and build up the chord tones from there. If there are any extensions (notes above the seventh 7), move them down an octave so that the entire chord fits within a single octave.
If you don't know the extensions, make an educated guess on what they would be. The first place to look when guessing the extensions is the melody. If the melody contains upper extensions that aren't written into the chord symbol, then add these into the chord symbol. For example, if your chord is
C7 and the melody contains an
A♭, view the chord as
C7♭13. (An exception: exclude a melody note from the chord if the melody note is merely a passing tone/approach tone. These tones don't necessarily define the chord.) If the melody offers no help, you can look to the left or to the right on the page, at the neighboring chords that occur immediately before or immediately after the unfamiliar chord. Try to find core notes from those chords which would work as extensions in the unfamiliar chord. For example, if your unfamiliar chord is
C7 and the very next chord is
E♭7, then try using a ♯9 (an
E♭) in the
C7 chord, because then the
E♭ will be a shared/common chord tone between the
C7 chord and the
E♭7 chord. If both the melody and the surrounding chords offer no help, I would suggest asking a band mate. ("Hey Jenna, do you play the
C7 chord with a flat 13?) This obviously won't work if you're playing solo or not in a performance setting.
Step 2: Arpeggiate the Chord
The next step is to arpeggiate the notes of the chord. As an example, let's say the chord is
C7♯9♭13. This includes the higher extensions that you've figured out. You want to play the chord like this, with all of the notes in a single octave:
and then you want to arpeggiate the notes, as bar 2 shows. (I've written the third note both as an
F♭ and an
E♮--we can't really identify which is correct until we identify the appropriate scale, so don't worry too much about which enharmonic spelling is correct.) As you go through the arpeggio, try to ask yourself if the notes form any recognizable scale. The arpeggio won't contain every scale tone, but you're looking for a close match with just a few omissions.
Step 3: Cycle Through the Inversions
I don't recognize a scale in bar 2 when I arpeggiate those notes. So the next step is to take the top note and move it down an octave, and then try again. (Alternatively, you could move the bottom note of the chord up an octave.) Continue cycling through the chord until something jumps out to you. In bar 4, I recognize an
A♭ maj scale, but with a
♭6. This is called
A♭ melodic major. So now I have my parent scale. Since I'm playing
C7, I would use the third mode of
A♭ melodic major, which is called phrygian ♭4. However, I don't need to know this name when I'm playing. All I need to know is that I'm playing an
A♭ maj ♭6 scale, or
A♭ harmonic major.
As you can see, the effectiveness of this approach will depend on how familiar one is with the major, melodic minor, harmonic major, and harmonic minor scales. Ultimately, the goal is to not have to think at all--in effect, to memorize which modes pair up with which chords. In a pinch, though, this method can work without taking too much time.
If you check out the circle of 5th you should be grand in finding out what keys to use. Such as the relative minor to the chord you are using. Even the relative 5th. If you have a C major chords you can use the 5th note in the scale and play the G major scale over it or even the G minor Pentatonic scale. There is also the obvious C major and C minor pentatonic scale. See this link: https://en.wikipedia.org/wiki/Circle_of_fifths
In almost any jazz song, you're going to hit lots of chords that aren't in the main key of the piece. Otherwise the song would be completely diatonic and boring. That said, there are a number of different ways to approach this but I think at the most straightforward level, you should learn (if you don't already know) the seven modes of the major scale and the triads and four-note chords that are built off of each scale. This will tell you what scales will always work over particular chords. For example, if you see a dominant 7th chord, you know right away that you can play a Mixolydian scale over that. And over a minor 7th chord, you can play Dorian, Phrygian, or Aeolian, and so on. Which of those you choose to play is an artistic decision you'll have to make at the time and will depend largely on the key and other chords around it. But then that gets into analysis and looking at the piece ahead of time, and it sounds like you're talking more about making a decision right in the moment. For example, the difference between Dorian and Aeolian is just a major 6th vs. a flat 6th. Which one sounds better in the particular context you're playing? Only your ear and experience can decide. The important thing is that you should be focusing on and emphasizing the chord tones (1, 3, 5, 7) in your improvisation and using the other notes of the scale as passing tones.
Another approach that can work is what David suggested in his answer. Think about the ways in which the chord you're playing differs from the key you're playing and adjust your scale accordingly. For example, let's say you're playing "All of Me". You start off nice and happy in C major, over a CMaj7 chord. Then the second chord is E7. That's a dominant seventh chord, and it's the fifth chord of A major--you're in a different key already. But you can think of it as "what about this chord is not in the current key and what should I change to fix that"? Well, you know that E7 is E - G# - B - D, so you could keep going on your C major scale but play G# instead of G. If you did that, you'd be playing a Phrygian Dominant scale (whether you know it or not), which could have a pretty exotic sound, but is perfectly legit. Or you could just do as noted above and say "Dominant 7th: that's a Mixolydian scale" and play that instead. This would mean you'd be playing F# and C# instead of F and C. It's up to you.
Learn the scale syllabus. This will allow you to know which mode to play on most common chords, including common chord extensions.