If both episodes were triggered by pain I suspect that your son has a very strong vagal response to pain. It is similar to when people see something that makes them "queasy" and pass out.
The pain triggers a nerve response that causes the blood vessels to dilate decreasing blood flow to the head leading to the fainting episode. These episodes resolve spontaneously and are generally not dangerous. I say generally because sometimes the victim will get injured from the fall, etc.
Care should also be taken to make sure that your son is supervised while swimming, etc. where a fainting episode could be life-threatening.
If the episodes are becoming more frequent I would recommend that you discuss this with your pediatrician as there may be some medications that can help.
Advice and opinions given are based on the information provided and must not be considered an official medical recommendation. The limitations of the internet prevent an appropriate evaluation. Always consult your doctor if there is concern.