There may be a nuance, so wait for someone more experienced to give you an answer, but here's what I know.
This ん is a contraction of the explanatory の. It has an explanatory tone to it. Also, when used at the end of a question, it gives the feeling of seeking an explanation.
"
「なんでテーブルの下で探してるの?」Why are you looking under the table?
「コンタクトレンズを落としたんだ。」I dropped a contact lens.