This is called BIRGing - Basking in reflected glory:
Basking in reflected glory (BIRGing) is a self-serving cognition
whereby an individual associates themselves with known successful
others such that the winner's success becomes the individual's own
accomplishment. ... The individual does not need to be personally
involved in the successful action. ... Examples of BIRGing include
anything from sharing a home state with a past or present famous
person, to religious affiliations, to sports teams.
Although BIRGing is a useful general term, social psychologists typically study more specific examples, particularly in social identity, where in-group affiliation with a sports team, political party, nation, etc, influences self-image, social status, and out-group derogation; or impression management, where affiliation with successful entities influences the perceptions of others.