This is a followup to benrg’s excellent answer, too long for comments. The quotation goes back to reminiscences of Einstein by the philosopher of physics Ilse Rosenthal-Schneider, from her doctoral studies in Berlin around 1918–20. This is related in (at least) four works by Rosenthal-Schneider:
a short typescript note in German dated 1957, online here as document 20-295 in the Einstein Archive, Erinnerungen an Gespraeche mit Einstein;
a chapter in English Reminiscences of Einstein, ADS bibcode 1980ssp..conf..521R, in the 1980 volume Some strangeness in the proportion: A centennial symposium to celebrate the achievements of Albert Einstein (ed. Harry Woolf), available at Library Genesis;
a 1980 book in English, Reality and scientific truth: Discussions with Einstein, Von Laue, and Planck, from Wayne State Univ. Press, which I haven’t yet been able to access beyond a few snippets from Google Books;
a 1988 book in German, Begegnungen mit Einstein, von Laue und Planck: Realität und wissenschaftliche Wahrheit, from Springer, Facetten der Physik vol.12, also on Library Genesis.
The later works repeat the story near-verbatim from the 1957 manuscript, so I think we can take that as primary. Below is my transcription of the section in question, along with the preceding anecdote for context, and with my (non-expert) translation interspersed. Since it’s rather long, I’ll give my own overall judgement in advance: Most likely Einstein did say something close to this quote — but he was probably at least partly joking. The typescript is from almost forty years after the events, so the details may well have been embroidered in memory (as other commenters suggest); but Rosenthal–Schneider was a serious and respected philosopher in a very scholarly tradition, so I would guess she was writing fairly carefully here (and might well have been working from earlier personal notes). However, the surrounding anecdotes clearly show that not everything Einstein said in these recollections was meant to be taken completely seriously — they often show Einstein joking, sometimes quite obviously and sometimes more drily.
Transcript from the 1957 typescript, page 2, sections III–IV:
III. Da wir zur Zeit seiner regelmässigen Vorlesungen dieselbe elektrische Bahn zur und von der Universität benutzten, hatte ich viel Gelegenheit, mit Einstein zu sprechen. Das waren durchaus nicht immer nur ernste, sachliche Diskussionen. Als ich eimal [sic] an der Haltestelle sagte: “Was würde nun sein, wenn der Bericht stimmte, dass der amerikanische Physiker (Miller?) wirklich den “absolut ruhenden Äther” nachgewiesen hätte?” Darauf er: “Dann wäre eben die ganze Relativitätstheorie Unsinn.”
During the period of his regular lectures [in Berlin around 1918–20], since we took the same electric train to and from the University, I had much opportunity to speak with Einstein. These were by no means always just serious discussions of factual matters. Once I said at the station: “And what would happen if the story were true, that the American physicist (Miller?) had really detected the ‘absolutely stationary aether’?” To which he replied: “Then the whole theory of relativity would be nonsense.”
IV. Als ich einmal bei Einstein war, um mit ihm zusammen eine Abhandlung zu lesen, die viele Einwände gegen seine Theorie enthielt, fand ich, dass er den Rand des Buches mit herrlichen Bemerkungen verziert hatte. An einer Stelle hatte der Verfasser geschrieben: ‘Es ist unverständlich, warum Einstein…’ (oder ähnlich). Am Rande stand von Einsteins Hand: “Bekenntnis einer schönen Seele”.
IV. Once, when I was visiting Einstein to read together a dissertation which contained various objections to his theory, I found that he had filled the margin of the book with marvellous remarks. In one place, the author had written: “It is incomprehensible why Einstein…” (or something like that). In the margin stood in Einstein’s hand: “Confession of a beautiful soul.”
An einer andern Stelle hatte er an den Rand geschrieben: ‘Adventavit asinus, pulcher et fortissimus’. Er amüsierte sich, dass ich sagte, es wäre nicht fair dass er das Buch vorher gelesen hätte; wir wollten es doch zusammen lesen. Er merkte aber natürlich, dass die reizenden Randbemerkungen mir riesige Freude machten. Plötzlich unterbrach er die Besprechung des Buches, ergriff ein auf dem Fensterbrett liegendes Telegramm und reichte es mir mit den Worten: “Hier, das wird Sie vielleicht interessieren”. Es war Eddingtons Kabel mit den Messergebnissen der Sonnenfinsternis-Expedition. Als ich meiner Freude über die gute Uebereinstimmung mit seinen Berechnungen Ausdruck gab, sagte er nur gänzlich unbewegt: “Ich wusste ja, dass die Theorie stimmt.” Und, als ich sagte, wenn es nun aber keine Bestätigung seiner Vorhersage gewesen wäre, entgegnete er: “Da könnt’ mir halt der liebe Gott leidtun, die Theorie stimmt doch."
In another place he had written in the margin: ‘Adventavit asinus, pulcher et fortissimus’ [‘Up came the donkey, beautiful and srong.’]. He was amused when I said it wasn’t fair that he had already read the book — we had been going to read it together. But he noticed, of course, that the charming marginal remarks gave me great pleasure. Suddenly he broke off the discussion of the book, seized a telegram lying on the windowsill, and passed it to me with the words “Here, perhaps this will interest you.” It was Eddington’s cable with the measurements of the solar eclipse expedition. When I expressed my pleasure at the good agreement with his calculations, he said just, completely unmoved, “Well, I knew the theory was correct.” And, when I said, what if there had not been any confirmation of his predictions, he countered “Then I’d simply feel sorry for dear God; the theory is true anyhow.”
The 1957 typescript moves on to other anecdotes, with no further comment on this one. In the 1988 book (and presumably the 1980), she adds a useful comment:
Hier verwendete er - wie so oft - das Wort "Gott" statt "Natur".
Here he used — as so often — the word “God” instead of “nature”.