It is usually best if Presidents and Prime Ministers stay out of each other’s elections . In free societies media interviewers can ask foreign leaders to make comments and they do so if they wish.
There are two big differences between President Obama’s intervention in our referendum and President Trump’s remarks yesterday. President Obama was clearly encouraged to intervene by the UK government who were committed to Remain. They used the intervention to try to persuade voters, drawing attention to it as part of their case in the referendum. The UK government did not ask President Trump to make comments yesterday and is not planning to use his comments in their election campaign.