It's not a must but it's better:
The issue is that when you apply to residency via ERAS the programs will look at your US experience and if they see that you have done clinicals in other specialty they may not like it and instead choose another guy who has done clinical externships in the same specialty (there are thousands of others applying with you and so you have to be competitive).
Closely versus remotely related specialties:
The other point is that psychiatry or neurology with internal medicine might be OK but they'll never like that you do a surgical rotation then apply for a medial specialty, I mean your combination should make sense.
Here's an example of my friend:
He wanted to go into pediatric residency and he lives in California and so he couldn't get pediatric externship instead he did family medicine externship and he asked the attending to write for him pediatric letters of recommendations in which they say he did FM but he excelled in seeing children and he really like pediatrics. Ultimately, this year he got into pediatric residency. :happy:So this is an example of closely related specialties which can work.
The elective story is different. Because all med students do electives in various specialties to get to know what they like. So the issue is much less sensitive as in the case of externships.