There is only one law which says exclusively. The "primarily" thing is an interpretation of the law by IRS.
> Spurred by such concerns over unfair competition and lost revenue, Congress enacted the UBIT. It taxed any trade or business regularly carried on by Section 501(c) organizations if the activity is not related—aside from the need for funding—to the organization’s exempt purpose.