As identified in the answer by HeyJude, this could be the story of the disappearance of Tang dynasty painter Wu Daozi (吴道子; variously transliterated as Wu Tao-tsz’, Wu Tao-Tsu, or Go Doshi). The earliest version of this story to appear in English was that of art collector William Anderson (1842–1900):
The legend, which celebrates the disappearance of the artist from the worldly stage, has a strong Taoist flavour. “In the palace of Ming Hwang,† the walls were of great size, and upon one of these the Emperor ordered Wu Tao-tsz’ to paint a landscape. The artist prepared his materials, and concealing the wall with curtains commenced his work. After a little while he drew aside the veil, and there lay a glorious scene, with mountains, forests, clouds, men, birds, and all things as in nature. While the Emperor gazed upon it with admiration, Wu Tao-tsz’, pointing to a certain part of the picture, said, ‘Behold this temple grot at the foot of the mountain—within it dwells a spirit.’ Then clapping his hands, the gate of the cave suddenly opened. ‘The interior is beautiful beyond conception,’ continued the artist, ‘permit me to show the way, that your Majesty may behold the marvels it contains.’ He passed within, turning round to beckon his patron to follow, but in a moment the gateway closed, and before the amazed monarch could advance a step, the whole scene faded away, leaving the wall white as before the contact of the painter’s brush. And Wu Tao-tsz’ was never seen again.”
William Anderson (1886). Descriptive and Historical Catalogue of a Collection of Japanese and Chinese Paintings in the British Museum, pp. 484–485. London: Longmans.
† Emperor Xuanzong of Tang (ruled 713–756).
Anderson did not give his source, but the earlier history of the story was given by Jan Cao:
Anderson’s English is, in fact, translated from Edo painter Tachibana Morikuni’s illustrated book, Ehon Tsūhōshi [Illustrated Book of All Treasures]. Published in Osaka in 1729, this book was a popular iconographical model for Japanese illustrators, with its ten volumes depicting famous figures and everyday objects. The word “Tsūhō” in the title literally means “ready money,” which suggests that users of this book should treat everything in this book as ready-to-use materials. This book had a wide circulation, and many scenes were reproduced by artists of later generations. […] Therefore, we could argue that popularity of Wu Daozi’s legend was partially due to the fame of Morikuni.
Morikuni was also not the first person to record this legend in written form. His story was translated from a Chinese source, Wang Yunpeng’s Liexian quanzhuan (1600) […] [Illustrated Comprehensive Biographies of All Immortals], a Taoist hagiography that includes biographies of 581 immortals. […] In Liexian quanzhuan, Wu Daozi’s disappearing is only one of the three legends recorded in his biography; the other two stories both claim that the animals—first a donkey, then a dragon—that Wu Daozi painted on the wall became alive. The story of his disappearing is the longest of the three:
There were some white walls in the palace, and upon one of them the Emperor Minghuang ordered [Wu Daozi] to paint a landscape. Daozi mixed some ink and spread the entire bowl of ink on the wall. He covered the wall with a piece of cloth, and unveiled it again after a brief moment. Then he invited the Emperor to look at the painting. Mountain, water, forest, trees, men, birds, and beasts, everything was included in the painting. The emperor looked throughout the picture, praised and admired it to the point that nothing could be added. Daozi slowly walked over, pointed at the picture and said, “there is a little hole under the rocky mountain. There is a Xian† in the hole, if you knock on it, he will definitely answer.” Then he knocked, suddenly the door opened, and there was a child servant standing on the side. Daozi said to the Emperor, “it is very beautiful in the hole. Please let me enter first, and I hope your majesty could enter after me.” Then Daozi walked into the mountain, and gestured at the Emperor with his hands. The Emperor could not enter; the door immediately closed, and nobody knew where Daozi went. The wall he painted is again white and bright as before, with no ink left on it.
† “Xian” in this context refers to a Taoist immortal.
Jan Cao (2019). ‘Benjamin’s Chinese Painter: Copying, Adapting, and the Aura of Reproduction’. In The Germanic Review 94, pp. 39–56.
Cao says that the story was popularized in Germany by the critic Walter Benjamin, who briefly alluded to it in his best-known essay, ‘The Work of Art in the Age of Mechanical Reproduction’:
Der vor dem Kunstwerk sich Sammelnde versenkt sich darein; er geht in dieses Werk ein, wie die Legende es von einem chinesischen Maler beim Anblick seines vollendeten Bildes erzählt
A man who concentrates before a work of art is absorbed by it. He enters into this work of art the way legend tells of the Chinese painter when he viewed his finished painting.
Walter Benjamin (1935). ‘Das Kunstwerk im Zeitalter seiner technischen Reproduzierbarkeit’. Wikisource. English translation by Harry Zohn.
and who gave a longer version in his memoir:
Sie stammt aus China und erzählt von einem alten Maler, der den Freunden sein neuestes Bild zu sehen gab. Ein Park war darauf dargestellt, ein schmaler Weg am Wasser und durch einen Baumschlag hin, der lief vor einer kleinen Türe aus, die hinten in ein Häuschen Einlaß bot. Wie sich die Freunde aber nach dem Maler umsahen, war der fort und in dem Bild. Da wandelte er auf dem schmalen Weg zur Tür, stand vor ihr still, kehrte sich um, lächelte und verschwand in ihrem Spalt.
The story comes from China and tells of an old painter who showed his friends his latest picture. It depicted a park with a narrow path through foliage by a stream, that led up to a small door that gave admittance to a little house. But when the friends looked around for the painter, he had gone into the picture. Then he walked up the narrow path to the door, stopped at the threshold, turned around, smiled and vanished inside.
Walter Benjamin (1938). Berliner Kindheit um Neunzehnhundert. In Gesammelte Schriften volume 4, p. 262–263. Tillman Rexroth.
Possibly Safranski got the story via Benjamin.