Since you ask for do's and don'ts, and I don't think anybody has said this in the answers so far:
It is unfortunately true in the UK, that it's probably safest not to wear team clothing for a team you don't know much about.
The simple reason is that if it just so happens to be a match day, or if the team has recently done something notable, or if you're in an area frequented by fans of a rival team, then some people will react to it. Some reactions will be negative, and some of those will be extreme. If you don't actually follow the team then you're gambling blind. If you know a bit about the team, you can judge when these less safe times and places are, and you can respond to any reactions in a way that makes sense from the football fan's POV (mind you, in the particular case of being told to throw your hat away, there's no response that makes particular football sense other than to start running sooner rather than later).
There are some pubs in London and elsewhere that ban team colours on match days. This is not because of anything to do with racism or nationalism. It's because some football supporters are prone to violence or trouble-making, and some supporters who aren't normally prone to those things get carried away when it comes to football. The pub doesn't want a lot of drunk people carrying on like that. The problem is to do with football, not race.
Furthermore, some fans object to people who aren't "proper" fans wearing team gear or otherwise giving the appearance of supporting a team "improperly". You would have thought that folks would get used to ManU being a global brand, but apparently not always. It's rare that a reaction would be anything like as extreme as the one you describe, and I wouldn't expect that to happen to very many people, but it doesn't surprise me in the least that it has happened to someone. I'm certain that there have been worse cases from time to time.
It's not as bad as wearing gang colours in the wrong part of LA, but it's the same type of "mistake". You have the legal and moral right to do it, but it's not advisable because certain people will react to it criminally. That's what happened in your friend's case. Even short of crime, if you pass a group of a rival team's supporters you half-expect to be shouted at, which can be intimidating if you don't know what it's all about. Or even if you do.
I don't want to blame the victim -- your friend was not at fault. The large majority of British people wouldn't support what happened. Football fans might get in your face, but will not normally attack you or take your stuff, or agree with other people doing so. However, the behaviour of the unpleasant minority is well known and yet difficult to wholly prevent.
I don't think this has much to do with nationalism or racism, other than that some people will come to the conclusion that you're not a "proper" supporter of a British club, or that you're fair game to be targeted, faster for an Indian than a white Briton. It would be nice to say that British football supporters are no more racist than the average population, and it might even be true, but I'm pretty sure that those who are racist are more likely to express racism loudly or in a physically intimidating way in the context of football. You hear racist chants at matches, or where fans are gathered before or after matches, and it simply wouldn't occur to the same people to chant those things if they were walking down the street together in a non-football context. It's slowly improving, and this is not a problem specific to the UK alone or football alone, but it's something visitors should be aware of if they're going to dabble in football while they're here.
So in short: the incident may well have been "racially aggravated" (in the legal sense of having been more severe or more likely to occur due to racism on the part of the perpetrator), but the root problem there isn't racism or nationalism. It's people being total jerks about sport.
In fact, based on what you say of the incident, it might not even be football-related. We know your friend's hat was stolen, and we don't know why. Might be football, might be racism, might be both or neither.
However, as far as advice on football, I would say the same thing: regardless of race, if you wear team gear then some people will react to it, and some of those people are nasty. You can encounter nasty people through pure bad luck, but doing so when wearing a hat for a team they particularly like or dislike is especially bad luck.
By the way, I've sort of assumed your friend doesn't know much about ManU. This might be incorrect, but you did say "Manchester United or some other famous football club", and you didn't say, "my friend, who has supported ManU avidly since birth". So I'm claiming fair assumption ;-)