Right,
the second one should be the first choice..
If consider strictly, the first one is wrong.
It is because Inversion should be used when asking directly.
The second sentence is correct and even if you are not writing 傳統英文, the first one is still incorrect. If you see people writing "Why oxygen is the most abundant element?", they're WRONG!...
The first one, which is "Why oxygen is the most abundant element?" can be a title of a report of stopry or whatever--BUT without the question mark...like "Why oxygen is the most abundant element"