Both are OK. It all depends on your perspective - no pun intended.
Teacher's view: The picture describes an action; it's about painting, not what the boy painted. So, us "a picture."
Student's view: The boy painted that picture there. We can both see it. We both know about it. It's shared knowledge. So, use "the picture."
In short, if the exercise is about what the boy painted, then "He painted the picture yesterday." If the exercise is about what the boy did, then "He painted a picture yesterday."
Now, it's your turn to decide. Should you mark the student's answer correct or incorrect?
All the best.