It is unclear whether this was a hallucination that Tenma experienced or if it was actually real. However the purpose of the hallucination was to enlighten the motives of Johan. When Johan was having a conversation with the orphan (when dressed as Anna, and I cannot remember that child's name... pardon me), Johan asked him questions as if he asked from himself:
''Did your mother hate you? If she didn't, why did she abandon you? Were you loved? Were you needed?''
The questions he asked from the child correlated with his questions he asked from Tenma; why was I born? Did my mother hate me? ...etc. We can also remember his mother swearing revenge upon the ones to execute the eugenic experiments, such as Franz Bonaparta and Peter Čapek, who were the head of this project; implying that his purpose to kill all these men was to avenge his mother... although, the intentions were too shady to be predicted.
Johan's fate following this is unclear, but his hospital bed is seen empty in the ending credits, ambiguously implying he has escaped from the hospital to do as he pleases. Most likely, he was going to attempt ''The Perfect Suicide'' all over again, and now that he remembered everything, he wouldn't fail in the mission twice.