Weil (because) and nämlich (namely) have very similar meaning, they are both used to express a reason. However, they are a little different.
Let's look at examples first.
Ich kaufe auf dem Markt ein, weil die Waren dort frischer sind.
I shop at the market because the products there are fresher.
Ich kaufe auf dem Markt ein, die Waren sind dort nämlich frischer.
I shop at the market because the products there are fresher.
We could translate the second example with "namely" but that would be misleading. In German, nämlich is much more common (and less formal) than the English "namely".
Difference 1:
The nämlich-sentence is a main clause, so the verb goes second.
The weil-sentence is a sub clause, so the finite verb goes...
at the end.
So in this sense nämlich is synonymous with weil (and denn). The tricky thing is that it doesn’t work the same way. You can never just swap a weil or a denn for a nämlich because of the word order!
Difference 2:
Nämlich and "namely" both come from der Name. The original idea was to use this word to introduce the name of things referred to before.
Kopernikus wurde zu einem Symbol, nämlich dem des Heliozentrismus.
Copernicus became a symbol, namely that of heliocentrism.
With time, it started being used to name reasons, but the cause and effect have to be unknown to the listener (or reader)
Ich bin zu spät, ich habe nämlich den Zug verpasst.
However, it doesn't make much sense if used to answer the question of "why?".
Ich bin zu spät, ich habe nämlich den Zug verpasst. (Nope!)
Ich habe nämlich den Zug verpasst. (Double nope!)
Weil ich den Zug verpasst habe. (Yes!!!)
Difference 3:
An additional skill nämlich has (as apposed to weil) is that it can be used to prompt a question.
Ich habe gestern eine tolle Serie angefangen.
I started watching a great series yesterday.
Nämlich...?
Being?/Which is?