According to the TARDIS Wikia page for the episode:
Writing in Doctor Who Magazine #495, Moffat confirmed that the portrait of Clara was painted by the Doctor himself.
Somebody on Reddit has posted the entire section from the magazine, and this is the exact line:
He knows that some of those hidden messages might just survive, because he knows the castle reset isn't perfect - the dust in the teleport room, the skulls in the water, the way the portrait of Clara he painted (of course it was him, the soppy old fool) has aged.
The gist is that he knows the castle reset isn’t perfect, so he leaves it as a message for a future version of himself. It wasn’t necessarily the very first iteration of the Doctor who painted the message, but a fairly early version.
Moffat further notes:
The other message that survived? In my head – and I suppose, only there – “I AM IN 12” is also written on the back of Clara's portrait. The trouble is, the Doctor draws too much strength from her smile ever to turn her face to the wall…