[subject] + 为什么 + [verb]?
Answer: 因为 + [reason]
为什么 asks for a reason. It goes after the subject and before the verb.
It can also open the sentence, which puts the whole question in focus rather than the subject.
Putting it at the end – nǐ你bù不qù去wèi shén me为什幺 – is wrong.
Unlike English, Chinese often keeps 所以 in the full answer as well: 因为下雨,所以我没去.
Both can ask why. 为什么 wants a reason and carries no attitude. 怎么 adds surprise – the speaker expected something else.
A teacher asking 你为什么迟到 wants an explanation. 你怎么迟到了 sounds more like disbelief.