In your first pair of examples, for and because of are equivalent semantically, unambivalent, and correct grammatically.
However, in your second pair, the second option is preferable
- They arrived late because of the heavy traffic.
This is because in the first option
- They arrived late for the heavy traffic.
there is a subtle ambiguity in the meaning of "for": We resolve it because we understand "heavy traffic" as something that can cause someone to be late. So we assume this is the "because of" sense of for, as in "You can't see the forest for the trees".
But if you didn't know that "heavy traffic" is undesirable, you might parse it as:
- [alas] They arrived so late that they missed the heavy traffic.
To better see how much this depends on the meaning of the NP that follows "for" (i.e., "heavy traffic"), we need only replace "heavy traffic" (a known hindrance) with a desirable event:
- They arrived late for the party.
We have no problem understanding that either. It means they were going to the party, and did not arrive on time. Of course, this is a different sense of "for". But it's the same syntax!
Now if we try to replace for with because of, look what happens:
- They arrived late because of the party.
Now we are not saying that they arrived late at the party; we are saying that they arrived late at some later, unnamed event, because they had been at the party.
So yes, there are cases where you cannot replace "for" with "because of".
(And there are cases where you not only could, but ought to)
Your second pair of examples are actually that type of case, syntactically—it is only semantics that allows a native speaker to discern the intended sense of "for".
Suppose we phrase it this way:
- But for the heavy traffic, they would have arrived at the party on time.
This is unambiguous, though it would be considered quaint or overly formal (in AmE).
But if we rephrase this same idea, in the simpler and more idiomatic style below,
- They were late for the party because of the heavy traffic.
we see a clear distinction between the usage of "for" and "because of". You could NOT replace for with because of; nor could you replace because of with for.