[subject] + 为什么 + [verb phrase]? 为什么 + [subject] + [verb phrase]? 因为 + [reason]
为什么 asks for a reason. It goes after the subject and before the verb.
It can also open the sentence, ahead of the subject.
It never goes at the end of the sentence.
In a negative question, 为什么没 asks why something didn't happen and 为什么不 asks why someone won't or doesn't do it: tā他wèi shén me为什幺méi没lái来 against tā他wèi shén me为什幺bù不lái来.
The answer starts with yīn wèi因为. In a full sentence, 因为 often pairs with suǒ yǐ所以 where English would use "because" alone.
Both can ask why. 为什么 wants a reason and carries no attitude. zěn me怎幺 adds surprise: the speaker expected something else.
A teacher asking 你为什么迟到 wants an explanation. 你怎么迟到了 sounds more like disbelief.
为什么不 + verb is often a suggestion rather than a real question, like English "why don't you". The expected reply is agreement, not a reason.