Earmarks should definitely be made to be relevant to legislation they're attached to, because the current system is too ripe for corruption. Attaching an ear mark to legislation in order to convince a member of a legislature to vote for that bill is tantamount to bribery, if not at a personal level.
Yes, earmarks should be required to be relevant to the legislation they are in! Not all members of Congress read through bills, and far too many irrelevant earmarks are added. Sometimes an earmark allocates money for projects that have nothing to do with the bill's subject matter, and the bill is approved by Congress, most of whom are clueless.