I would like to know why humans can detect a note out of tune relative to the scale or harmony. We seem to be born with the ability to notice, so why can't every able-hearing person sing or play an instrument in tune?
The foundation of scales and relative tonality is the fact that all humans are innately able to detect intervals. We can detect an octave because an octave is two notes where one is twice the frequency of the other. Similarly, there are basic proportional relationships between the frequency of two notes that are fifth, or a third, or a whole step apart but they are harder to detect because the relationship is less obvious. In a fifth, for example, one note is a vibration 2/3 as fast as the other. The innate ability to react to relative intonation gives rise to the fact that minor keys sound different from major keys, and notes out of tune often sound "wrong" even to people with no musical training. The less obvious a tonal freqency relationship, the more learning is involved. Almost everyone can tell that an octave sounds "right" and a 7 1/2th is "wrong" with no training. So far I have not found any research indicating that any culture has a scale system that is not based on the octave (see this article, these music theory class notes and the Wikipedia section on consonance and dissonance which answer your question better than any of the answers here). Because of the instrinsic physiological phenomena of the interval, Eastern and Arabic scales are based on the same intervals as Western scales and just have more or fewer steps. Arabic, Chinese, Japanese, and Ancient Greek (Syntolydian) musical scales are all based on the octave, demonstrating that the human ability to detect that interval is nature rather than nurture.
The fact that an A above middle C is 440hz, however, is arbitrary ("absolute") and therefore must be learned. Some people seem to be better at learning to recognize absolute frequencies and these people are often said to "have perfect pitch." This perfect or absolute pitch is what is required to tune an instrument or sing a certain pitch with no reference. It is not held in common across cultures; for example the frequency of the base note Kung in Chinese music was often changed by the emperor (although it is usually treated as almost the same as a western F). It must have been very hard to learn perfect pitch when your base note changed over time!
In conclusion, YES, we are born with the ability to detect a note out of tune relative to another note (helps if it's an octave or fifth), but NO, we are not born with the ability to detect a note out of tune on its own.
If one watches those [insert nation here]'s Got Talent programmes, especially the audition phase, most people will be able to tell the difference between people who are good at [insert talent here] and those that are not.
Having the performer's skill is not required in order to be a judge, you're only required to understand what the performer is trying to achieve.
Are we born with this ability? Probably not, no. Some genres of music (and other art forms) are let's say 'an acquired taste'.
This study says people prefer music that is 'familiar' http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0027241. I remember one of my lecturers at university once talking about how it is our experience matching our expectations that results in enjoyment. There are sometimes musical pieces that take a few listens before we realise how beautiful they are.
I don't think we're born with it, I think it is learned, based on exposure.
Everyone is "born with" the ability to learn a language, but not everyone pays attention to their spelling.
It's simply a matter of being attentive to the right things and learning to increase your accuracy and responsiveness.
Both language and music are learned skills, but only the groundwork is in our biology. Everything else is education, be it explicit or immersive.
"I like to know why humans can detect a note out of tune relative to the scale or harmony."
Why questions are never easy to answer since it is not clear what the one who asks is prepared to settle for.
"We seem to be born with the ability to notice,"
I would say that this is not as easy as it seems like.
I was born and grew up in Western Europe, and I can distinguish consonance and dissonance in a well-tempered tone system. At the same time, I can enjoy, say, vocal music from the middle east, and I can sense that they use tones that are outside the western well-tempered tone system. However, I cannot sense whether they sing "out of tune"; It seems this is very much something that you learn, not something that is inbred.
"so why can't every hearing abled person sing or play an instrument in tune?"
This seems yet something completely entirely different. To me, being able to hear, is entirely separate from controlling your voice, and again entirely separate from playing an instrument.
The answer in my experience is both yes and no.
First, not all human ears are equally sensitive to differences in pitch. Also, an ear which can discriminate well in one pitch range may have more difficulty with a different range. For example, a musician I know can tune a guitar by ear very quickly, but struggles to tune a bass guitar. His ear just has more difficulty with the low ranges.
Second, identifying when two pitches are different is a skill that improves with practice. A musician's ability to identify notes out of tune improves as their experience with their instrument increases.
Also, you asked about singing. To sing in tune is very different from tuning a guitar. You have to learn the intervals between the notes, so you can "hear" the next note in your head before you sing it. You also have to train your voice, so it can reliably produce the note you hear in your head. People who sing along with the radio may have learned the pitches through listening to the song repeatedly, but without practice they will probably not sing every note in tune.
So my short answer is that most humans are born with what they need to make music, but to sing or play an instrument in tune requires practice and training.
"We seem to be born with the ability to notice,"
This might be the norm, but exceptions do exist.
I personally can't tell when people are out of tune (unless they are drastically), neither can I tell that two notes are one octave apart, they just sound like different notes. Additionally, when a key change happens mid song (typically for the last verse) I have no idea that it's happened.
These factors mean that even when following music or other singers I am frequently told I'm out of tune - however I tend to be better when I've got someone who's singing in a pitch I'm happy to follow, trying to follow someone 1 or 2 octaves away from my range will mean I'm going to be out of tune.
You'd like to know why we (or many of us) are born with the ability to detect a note out of tune. I think I can speak for all of the readers here when I say that we would all love to know why we are born with any ability or disability. In fact, I don't think it's much of a stretch to say that we would all love to know why we are born at all. Truth is, we don't know, although some of us won't admit it.
"Tone deafness" is actually very common. Just listen to an average crowd singing "happy birthday" and this will become clear. The ability to recognize, organize, and reproduce sounds that you hear is innate, much in the same way that the ability to recognize, organize, and reproduce colors that you see is innate. So, just as color blindness is something you are born with, tone deafness is also.
A good (not perfect, see Roland's answer) way to test for tone deafness is to see if a person can reproduce a note that they hear. If not, then that person is very probably tone deaf.
My father is tone deaf. This became clear to me at a very early age, because he sang a great deal anyway. It became clear early on that when it came to songs, Dad knew the words and Mom knew the tunes. My father also picked up the recorder and learned to play, however he would not know if he was missing a sharp or flat from the key signature until one of his kids hollered to him to fix it.
My mother, on the other hand, is very musical. Of their seven children, five can sing in tune, one can sing pretty much in tune, and the other is a really, really nice guy. Interestingly, one of his kids shows considerable talent for singing.
So, I believe that the ability to recognize pitch is either there or not there. If you have it, you can improve it, but if you don't have it, nothing that you do will put it there.
I have occationaly come across articles about singing birds have absolute (perfect) pitch, which indicates that this is not taught, but based on nature. When I searched for this now, I found this interesting publication by Terry Bossomaier and Allan Snyder. They claim that the mechanisms for absolute pitch exist in us all, but access is inhibited during early maturation.
They also have a section about animals related to this (on page 3 in the PDF), where they reflect about some singing birds using scales in their singing:
A large part of the publication is about methods describing how absolute pitch may be switched on by turning off parts of the brain responsible for the inhibition.
As for why not everyone is able to sing in tune according to their ability to recognize out of tune, there might be several reasons.