No, it is not illegal for a free US citizen. However, prisons specifically prohibit gang membership because prisoner are not free citizens. Many gang members in prison try to conceal their membership and security guards refer to gangs as "security threat groups" as a way of denying legitimacy.