Shanks attacked Bartolomeo's crew because the latter had burned his flag, an act considered an affront and a declaration of war in the world of One Piece. As an Emperor, Shanks had to react to maintain his authority and protect his allies.