Usually bodies of Gods are having super human capabilities. Apart from the fact you mentioned in your question, as per the legend book, Ram Charit Manas, written by Tulsidas.
"Even as Surasa expanded her jaws Hanuman manifested a form twice as
large as her mouth.When she further expanded her mouth eight hundred
miles wide, Hanuman assumed a very minute form"
Sundar Kanda, page 820, sloka 5
So Hanuman's body was not a normal human body which we can think of and make interpretations with our senses. These are kind of mystical powers which we ordinary mortals don't have. That's why they are given the status of God in mythology.
So in my opinion Hanuman ji did not need any surgery, he showed by his powers that only lord lives in his heart and to prove his point he had to open his chest.
In our present age there has been a great saint who with the help of Hanuman ji was able to do miracles though he never claimed himself to do any thing and mentioned always it is Hanuman ji who is doing all this. He is known as Neem Karoli Baba you may read more about him on google for a starting I am giving below a couple of links.
Neem Karoli Baba
Many ascetics in Himalaya are able to develop such powers so it is no wonder that Hanuman ji had the power to heal himself.
To have an understanding of how siddhi's work is important to understand the answer
you may consider reading a couple of books to understand
an understanding of Kriya yog googling about Kriya Baba and Kriya yog may act as starting point.