You can think of music theory in two parts :
- The 'scientific' part : Physics and psychoacoustics
- The 'stylistic advice' part : Patterns and practices that have been observed to be common to certain musical styles - i.e. if you want this kind of sound, you should do this.
From the scientific point of view, maybe we can observe that
Some notes have fundamental frequencies that are part of the harmonic series of other notes (or have an octave relationship therewith), giving them a close relationship and making movement between them easy.
(obviously) some notes are close in pitch, giving a natural ascending or descending motion when you move from one to the other.
We tend to expect pieces of music (or sections thereof) to move towards a root note that the harmony is based around.
The diatonic scale, which is what you are using when you are writing music in a key, has been designed to take those things into account , and so if you are using it, you will have lots of opportunities for good, scientifically-sound harmony :). However, the diatonic scale (and the whole idea of keys) is a stylistic choice. It's certainly not the only way to write good-sounding harmony - for example, the 12-tone equal tempered scale allows many harmonic possibilities that work well but go outside the bounds of a particular key.
So, to ask
When does it make sense to have chords that are out of key? to me is slightly backwards thinking. If you are restricting yourself to the notes (and therefore chords) in a key, it's because you've already made a stylistic decision to do so, because you want that particular sound. If you haven't made that decision, then you're not in a key (in the sense of sticking to the notes of the diatonic scale), and therefore question you asked doesn't arise.
Put another way - you can always do whatever you want, and 'making sense' doesn't come into it.
However, if we consider the 'stylistic advice' that music theory gives us about particular styles : to say
From musical theory I know of no reason not to use any of the chords of the key in any order indicates to me that you could usefully read around the subject a bit more! A lot of music theory is concerned with ways to choose your harmonic motions. Some starting points to look at would be:
- Functional Harmony
- How to set up modulations
- more advanced ideas such as secondary dominants
- Jazz harmony and substitutions
- The blues scale
- "standard" chord progressions:
A lot of modern music comes from a mixture of classical and common practice harmony, and blues and folk scales and modes. Personally I think this sudden fusion of styles has caught the music theory field on the hop a little, and I've not read anything that really deals with the ways in which the various musical traditions are blended together to create the common effects we see in popular song - unfortunately you often hear some suggestion that 'chord borrowing' is going on, and not much more. Maybe someone better-informed can suggest something! Still, once you've learned about the various traditions I've mentioned, you probably have most of the tools you need to make sense of songs in your own way.