What I understand is that the の is used when an explanatory tone is needed, but is there anything fundamentally different with these statments and which is used when?
The former, なんで日本語を話せますか, is plain unnatural, and you should always construct a sentence like the latter. A good rule of thumb is that なんで/どうして is almost always used with explanatory の/ん.
- Short questions like "なぜか?", "なんでですか?" and "どうして?" do not require の/ん. (Although it's common to add な/の like "なぜなのか?", "なんでなんですか?", "どうしてなの?" The difference is very small.)
- In an embedded question, の/ん is not required.