To answer your question directly, no; 2 cannot be used in place of 1.
The heart of the meaning here is that she came up from somewhere unknown to the speaker.
The speaker indicates this lack of knowledge by suggesting or asserting that there is somebody who knows where, but that (by contrast) it is not the speaker.
Some ways of expressing this are to say somewhere, nobody knows where, (only) God knows where, (only) "goodness" (as a stand-in for directly saying God) knows where. This is the sense which lies behind this phrase. Parsing by rules alone can result in constructions which do not convey the same meaning.
Neither is this a different way of asking the question. The speaker merely omits location information by asserting that it is largely unknown. The speaker has dismissed the location part of the travel as insignificant (and perhaps unsavory).
I agree with you that there is a problem with this construction if not seen as a phrasal element. I think (not sure about the nuts and bolts here) that this would benefit from the hyphen treatment for compound modifiers, e.g., goodness-knows-where, to mark it as a collective modifier, rather than a grammatical sequence. This way, we can simply call the whole thing an adverb of location and move on.