In the medieval context, the concept of loyalty was interpreted primarily as hierarchical loyalty to one's lord: a vassal to his liege, a servant to his master, a son to his father, a wife to her husband. While not unconditional and (as I have noted elsewhere) based on reciprocal obligations, medieval loyalty was nevertheless more comprehensive and consuming than modern notions. Loyalty was expected "unto death" with very few exceptions. Collateral loyalty -- to siblings, comrades, companions and compatriots -- was more similar to what we know today, i.e. was more voluntary and less binding. However, for a tenant-in-chief to the crown, as Ibelin was, the defining loyalty was that to the king.
The test of Balian d'Ibelin's loyalty to the crown came after the death of Baldwin V of Jerusalem; up to that time he like the bulk of his contemporaries was steadfastly loyal to the kings of Jerusalem. On the death of the child-king Baldwin V, Sibylla, the eldest of the two surviving children of King Amalric I and mother of Baldwin V, was the most obvious candidate to succeed to the throne. Unfortunately, she was married to a man who had lost the trust and respect of almost the entire High Court of Jerusalem. To gain support for her coronation, Sibylla promised to divorce the mistrusted Guy on the condition that she be allowed to marry the man of her choosing thereafter. Her supporters agreed to this condition, only for her to betray them by naming Guy de Lusignan as the man of her choice. With the help of the Patriarch and the Grand Master of the Knights Templar, she had herself crowned Queen of Jerusalem in the Church of the Holy Sepulcher and then crowned Guy as her consort.
The problem was that the constitution of Jerusalem gave to the High Court of Jerusalem the prerogative of electing the monarch, and Sibylla had by-passed the High Court. Without the consent of the High Court, she and Guy were usurpers. The High Court attempted to crown her younger sister instead of her, only to be betrayed by her sister's husband. who refused to play the role of consort to his wife. At this point the opposition of most of the barons collapsed, and Guy and Sibylla were recognized as de facto King and Queen.
Two barons, however, refused to accept the usurpation. One was Raymond of Tripoli, who promptly signed a separate peace with Saladin. The other was Baldwin d'Ibelin, Balian's older brother. The elder Ibelin renounced his two baronies in favor of his son, turned this infant son over to the keeping of his younger brother and left the kingdom voluntarily. Balian, in contrast, placed the interests of the kingdom over his personal pride; he took the oath of fealty to the hated Guy de Lusignan. Not only that, but he was one of the intermediaries sent to reconcile Tripoli with Lusignan, and after the death of two of the others, the main spokesman.
An even greater indication of his loyalty was that despite his reservations about Guy de Lusignan's leadership, he dutifully mustered his feudal levees and his knights when Guy summoned them less than a year later. Most significantly, when Guy overrode the advice of his barons and ordered the advance on Tiberias, Ibelin commanded the rear-guard of the Christian army that marched -- against his better judgement -- to destruction on the Horns of Hattin.
It was not until after the death of Sibylla of Jerusalem, when Lusignan lost his last shadow of a claim to the throne, that Balian abandoned Lusignan. Following Sibylla's death, Ibelin's loyalty turned to the last remaining blood descendant of the royal family, the only surviving child of King Amalric, Isabella. But Balian's loyalty to Isabella was not mindless or blind. Because she was married to a man incapable of defending the kingdom, Ibelin led the faction of barons that insisted Isabella be separated from her ineffectual (and allegedly effeminate) husband before taking an oath to her. Only after she had been divorced from Humphrey de Toron and married to Conrad de Montferrat did the barons of Jerusalem, including Balian d'Ibelin, take an oath of fealty to her. Ibelin remained loyal to this oath despite Richard the Lionheart's fierce and tenacious support for Guy de Lusignan.