The ambiguity occurs because of the way that adjectives bind to the (normally) closest phrase.
Consider a parallel:
I still have sand in my shoes from Hawaii.
What is from Hawaii? The sand or the shoes?
(Edit 1. Note that there is an ambiguity in the sentence that does not involve negation.)
When I read the example, the first interpretation came to mind, probably because not was closer to come than to rain.
You could avoid the ambiguity in different ways.
(Edit 2. Removing "John didn't come because of the rain." as it does not remove the binding ambiguity.)
A. John did not come, as the torrential rain prevented him. (Slight expansion lessens the ambiguity.)
B. John came, not because of the rain, but driven by his longing for Helen. (Explanation makes it clearer in the reader's mind.)