Venice was part of the Exarchate of Ravenna, one of the provinces in the western part of the Empire when Justinian reconquered parts of Italy in the 6th century. But Justinian’s conquests didn’t last long and Venice was soon outside the direct control of Constantinople. By the 8th century the Doge was recognized as the semi-independent leader of Venice - but he was recognized by the emperor in Constantinople, using an imperial title. The title “dux” is originally Latin, but it was used in the Greek part of the Empire too (“doux”), and the Greek form evolved into the Venetian title. So both Venice and Constantinople considered Venice to be part of the Empire, although of course the Venetians felt they were far more independent.
Geographically, Venice was much closer to the church in Rome and the expanding Carolingian empire. Charlemagne, and the Byzantine emperor Nicephorus, both recognized Venice’s independence and its important place on the border of both empires’ spheres of influence. After that, Venice was mostly concerned with expanding control over the Adriatic, and the islands on the eastern shore of the sea - i.e., over territory that was nominally Byzantine.
By the 10th and 11th centuries, the Italian side of the Adriatic was under the control of the Holy Roman Empire, the Papacy, and the Normans. The Normans, especially, were enemies of the Byzantines. Southern Italy was supposed to be under Byzantine control too, but the Normans conquered all of that, and they attacked Byzantine territory in the Balkans and the Aegean as well. Venice remained allied with the Byzantines against them.
The emperor in Constantinople recognized Venice’s role in trade and keeping the peace in the Adriatic. By the 11th century there was a big merchant community living in the Byzantine city of Dyrrhachium on the Adriatic, as well as in Constantinople. The “Golden Bull” of Emperor Alexios I in 1082 (or maybe 1092) gave the Venetian merchants trade privileges in the empire. The Empire also had hardly any navy of its own, so it relied on Venice to provide it with a navy everywhere else too, not just in the Adriatic.
“…by the accession of Alexios I Komnenos, the Byzantine navy had virtually disappeared and certainly could not project its forces far afield. Faced by the attack on the Balkans in 1081 by the Normans under Robert Guiscard, Alexios had no choice but to offer a new imperial chrysobull to Venice, granting extensive economic privileges within the Empire to her merchants in return for the assistance of her fleet against the Normans.” (Pryor and Jeffreys, Byzantine Navy, pg. 87)
Twenty years later, the First Crusade established a Western European kingdom in the Near East, and Venice was right there along with them. The Venetians, Genoese, Pisans, and other Italian city-states set up their own trading colonies in the crusader cities on the Mediterranean coast. Now they had outposts at the end of the trade routes from Asia, they had easier access to Egypt, and they still had their flourishing commercial neighbourhoods in Constantinople. They performing the naval and commercial maritime activities for the Byzantines that the Byzantines didn’t, couldn’t, or wouldn’t do by themselves.
Not everyone in the Byzantine Empire appreciated this. Byzantine Greeks considered the Venetians and other Europeans to be crude and vulgar; Niketas Choniates talks about “the driveling of the Latins and…their arrogance”. Maybe they were valuable members of community, but they made sure everyone knew it, or at least that’s how some Greeks felt. The empire was also heavily influenced by their new neighbours in the crusader states, and the royal family often married into crusader and other Western European families, so some people thought the westerners had too much influence in government and society as well as the economy and the military.
The Italians typically didn’t really get along with each other in Constantinople, so that was another problem in the eyes of the Greek inhabitants. In 1171 the Venetians and Genoese had a mini-war within the city and the Venetians were kicked out and their property was confiscated. Clearly they couldn’t be trusted to behave themselves!
Meanwhile, in 1176 the Seljuk Turks defeated the Byzantines at the Battle of Myriokephalon. Even more than the Battle of Manzikert 100 years earlier, this was the battle that really ended Greek control of Anatolia. The emperor, Manuel I, died a few years later in 1180, and his wife, the crusader princess Maria, ruled as regent for their young son Alexios II. It was already easy enough to blame foreigners and minority populations for a defeat in battle, but now a foreign women was ruling the empire. That was intolerable for at least one person - Manuel’s cousin Andronikos Komnenos, who overthrew Maria and Alexios II in 1182.
Andronikos’ arrival also sparked a riot against the Venetians and any other Latins they could find. Actually the Venetians probably weren’t very numerous in Constantinople at the time, since they had all been kicked out 10 years earlier. But the Genoese and Pisan neighbourhoods were certainly destroyed. Their churches were also attacked. Survivors reported that the Greeks killed the Papal ambassador, cut off his head, and dragged it throughout the streets tied to a dog’s tail.
While the Greeks thought the Latins were arrogant and violent, Latins felt the Greeks were untrustworthy. The crusader historian William of Tyre, who heard all about the massacre from refugees, called the Byzantines “perfidious” and “a brood of vipers”. A few years later, some of the Third Crusade passed through Constantinople and there was almost open warfare with the Empire. Only twenty years later in 1202, the Venetians managed to divert the Fourth Crusade to Constantinople, quite possibly in revenge for the expulsions in 1172 and the massacre in 1182. The entire empire was temporarily destroyed.
So, in brief, the Byzantine Empire did sort of have a love-hate relationship with Venice and other westerners, but their actions weren’t really random. Venice was a part of the Empire, and although it was de facto independent, it was still an ally of the Empire and provided valuable commercial and naval services. There wasn’t really any flip-flopping, just a lengthy deterioration of the relationship. The Greeks probably were envious; David Nicol describes it as “years of resentment.” They wondered why they couldn’t do these things themselves. Unfortunately they concluded that westerners had infiltrated the empire and were actively preventing Greeks from succeeding. Basically, when things went wrong, it was easy for the Greeks to be xenophobic and blame foreigners and minorities.
Sources:
Donald M. Nicol, Byzantium and Venice: A Study in Diplomatic and Cultural Relations (1992)
Thomas F. Madden, Venice: A New History (Penguin, 2013)
John H. Pryor, and Elizabeth M. Jeffreys, The Age of the Dromon: The Byzantine Navy, ca. 500-1204 (Brill, 2006)
O City of Byzantium: Annals of Niketas Choniataes, trans. Harry J Magoulias (Wayne State University Press, 1984)
William of Tyre, A History of Deeds Done Beyond The Sea, trans. E. A. Babcock and A. C. Krey (Columbia University Press, 1943, repr. Octagon Books, 1976).
Also see some earlier answers about the 1082 Golden Bull by u/Total_Markage and myself.