Answer:
Diplomatic immunity applies to Obama only when he is representing the US in a foreign country. It is hard to say what would happen if a visiting head of state were to commit murder and it would depend on the evidence against him, I would think. If he was indisputably guilty , immunity would likely be waived and the man tried where the murder was committed. If it seemed that the charges were questionable, the US government would argue diplomatic immunity and try to get him brought back to the US while futher investigation went on and try him here if there was enough evidence to indict him.