Of course the US wanted the UK to remain. The US and the UK are rather similar in a lot of ways. The Americans wanted the British to stay in so that they would make the EU more open, free trade, more friendly to the Atlantic countries, etc.
It's because he is a foreign politician, it is seen as inappropriate. No one really cried foul when American CEOs or banks came out and said that the UK should Remain. To be fair many political leaders came out and said that they preferred the UK to remain but I still think it's inappropriate for foreign governments to comment on domestic elections or referendums.
It's not at all clear that what he did was counterproductive. I'm not sure why you're asserting that. Regardless, obviously this was something Cameron was okay with and I'm not going to fault Obama for deferring to his judgment on a matter of UK politics.
But, yes, he was trying to explain to voters that there were costs to voting Leave that they were not taking into account. Why is this a bad thing?
It's because he is a foreign politician, it is seen as inappropriate. No one really cried foul when American CEOs or banks came out and said that the UK should Remain. To be fair many political leaders came out and said that they preferred the UK to remain but I still think it's inappropriate for foreign governments to comment on domestic elections or referendums.