"Why do your ears hurt?"
The ん is an abbreviation of の. This is the grammar for のです, which can be shortened and made casual by saying のだ, んだ, or なんだ.
On the technical side:
We use の before です when we want to explain or emphasize something. This is just personal, but I feel like I am a little removed from an emotional stand point if I don't use の. But then, I drop my casual ん's into everything : D.
The following would feel like a statement or fact.
いたいです。 It hurts.
Using the ん explains the reason why or emphasizing how much you Re feeling. 痛いんです。 (I feel/ Because) it hurts.
おばけやしきはこわいです。 Haunted houses are scary.
おばけやしきがこわいんだよ。 (I feel like) haunted houses are scary!
When translated they would be the same in English, but the sentence sounds softer with ん and shows more emphasis.
That is a good question. : )
I would say, not exactly. It is probably closer to say it is used in situations with a previously established foundation.
EX 1 - Response based on a previous conversation:
Ami told Masa that she wouldn't go to an event. On the day of the event Masa found out that Ami suddenly decided to go.
In this case he could say 「行くんだ。」 (Oh, she is going./Oh, she decided to go.). He could also say「来るんだ。」if he is at the event and heard about Ami.
This would most likely be a reaction to second hand information.
EX 2 - Response based on a situation:
Yumi was not able to sleep and the next morning at work she starts spacing out and sighs often. Someone who sees her could say 「ねむいんですか。」(Are you sleepy?) in response to how Yumi looks.
In this way we would be asking a question based on what we saw.
EX 3 - Response based on a current conversation:
Nina tells a friend she don't feel well. Her friend could try to guess what is wrong by asking questions like「つかれているんですか」(Are you tired?) or 「お腹がいたいんですか」(Does your stomach hurt?).
In this way we would be responding to what someone has said.
So it can be first and second hand information.
I wrote: あなたの耳はなぜ痛いですか？and it was wrong. Does なぜ have to come at the beginning? And is ん necessary? I have read the comments above and understand the subtle difference (well...I THINK I understand the difference) of ん but as translated would, なぜあなたの耳は痛いですか？be acceptable? And I'm okay if for the purposes of these lessons that we are focusing on the use of ん。
なぜ usually comes at the begining of a sentence or before the verb or noun (there are exceptions to every rule). If you said "your ears why hurt" in English it would sound a little odd. We still understand what is being asked, but the order is a little mixed up. Japanese is similar.
You do not need the ん. Many people I know from Kansai don't use it, whereas many of my friends from Tokyo do.
These would be the same. Why do your ears hurt?
Note: You can use it if you want, but we do not need to have あなた.
Duo might not accept the different sentences because they are focusing on a certain type of grammar, but there are usually many ways to say the same thing.