[reason] + ,难怪 + [clause]
难怪 + [clause] + ,原来 + [reason]
难怪 goes at the start of a clause and says you now understand something that had puzzled you. The reason usually comes first, and 难怪 introduces what it explains.
The order can also run the other way: 难怪 first, then the reason with 原来.
难怪 can stand alone as a reply: 难怪! "That explains it!"
难怪 starts its clause, before the subject. It can't sit between the subject and the verb.
What follows 难怪 is something that now makes sense. It can't introduce a surprise or a contradiction.
At the end of a sentence, 也难怪 means "it's understandable": no one can be blamed for it.
怪不得 means the same and is a little more colloquial.