I want to know what it means, in terms of the scales and chords involved, when we say that a song is played in a certain 'key'.
A key is simply telling you the note that will be perceived as tonic (you'll sound at rest on that note) and the expected harmony and melody.
For example, when someone tells you a song is in the key of C major you can expect a majority of the song to use notes from the C major scale and use chords built from the C major scale and the harmony and melody constructed will want to go to C. There are almost always other chords and scales that are used, but they will still have the goal of making C sound like the tonic unless you modulate which means change keys.
When someone tells you a song is in the key of C minor you can expect a majority of the song to use notes of the C minor scale and use chords built from the C minor scale and the harmony and melody constructed will want to go to C. It's the same idea as above, just now we are using ideas from C minor to base the melody and harmony on.
Said another way, when we speak of a musical key we are referring to a much larger concept than just a scale or a "key" note (tonic). Of course, a musical key includes a tonic and a scale (mode), but the psychological magic of a musical key is not found in memorizing scales and chords, it is found in discovering the family relationships between all the constituent parts of a chosen "key." For example, the harmonic qualities of chords, chord changes, intervallic movement in melody, and predictable tonal behaviors used in improvisation are all implied by the key.
A musical key describes a context for music; it is a structural system that creates meaning for any given note or set of notes used in the music--a palette of related tonal materials used for emotional communication. Using a musical key creates a context in which to measure movement, to create the sense of a musical journey, a point of departure for materials that are not in the key, and a sense of coming home at the completion of a journey. It is this movement within a specified key that creates emotional communication and connection.
A musical key can also be figured as a solar system of sorts where the tonic (key note) is the gravitational center of the key. The tones supplied by the scale are the building blocks for melody and harmony/chords within the key, where each tonal degree of the scale occupies a fixed intervallic distance away from the key center. When you understand the cosmos of the key, you understand how the movement of melodic tones, intervals, scale tones, chord tones relate and behave with each other.
Melodic tones travel in various tension and release movements in relation to their distance from the key note. Melodic tones are derived from the scale of the key and live inside of chords.
Chords are little subsystems inside the larger key and have their own tonal centers inside the smaller chord structure. Each voice in the chord orbits around the central chord tone (chord root), while each chord system has an orbital relationship to the larger key center (tonic).
A key is the tonality that is central to a piece of music. What that means is that a key is based on a tone and a structure built around that tone. It is this structure that provides context and meaning inside the music.
The key of a song is usually indicated at the beginning of the sheet music. As in C major,(or A minor) which has only 'ordinary' notes - no sharps or flats - will have nothing at the beginning, whereas Eb (or C minor) will have 3 flats indicated at the beginning of each line, because that key will usually use 'ordinary' or natural notes, with the exception of Bb, Eb and Ab.
As Dom points out, there will be a 'home' note and chord that a specific key gravitates to, and that's the name the key takes on. Scales are just those special notes from a specific key, put into order, and will be the mainstay of notes contained in most tunes in that key.
Since chords are made up from the notes in the scale, thus the key, they will generally contain three or more notes from that scale, and usually be used under some of the notes contained in the chord played in that bar.
AS Dom almost said the key of a piece is a psychological effect. Being "tonic" and "sound at rest on that note" are alluding to the fundamental concept as being a psychological reaction. Key signatures clearly are not adequate since they each have two keys. Also there is no definite relationship between the notes played and the musical key. There are scales and chords which are generally believed to have this psychological effect but they are not required to be used to be in a particular key.
If anyone knows of any experimental studies quantifying this effect I'd love to hear about them.