In 1157, the heir of Jerusalem, Amalric, forced Agnes of Courtenay to marry him. In 1163, he divorced her due to opposition from the nobility, consanguinity, and her lacking political value.
Agnes's father had held Edessa but that had been lost in 1146 and her father had been imprisoned and blinded, so she didn't hold any political value even then.
So why did Amalric want to marry her? As heir of Jerusalem I would think he would have a plethora of potential brides. Was he enamored by her beauty, did he plan on trying to retake Edessa and attempting to seize it for himself? Or something else?
The story that Amalric abducted Agnes and forced her to marry him is from the Lignages d’Outremer, which is a strange source, dating from much later in the 13th century, and apparently containing oral traditions from families in the crusader states. It seems pretty likely that the Lignages contains some clearly legendary, exaggerated, or outright incorrect material, especially when we can compare it more contemporary sources from the 12th century.
So how did these two end up together? Well Agnes was the daughter of Joscelin II of Edessa, who, as you mentioned, lost Edessa - twice actually, first in 1144 to Zengi of Mosul, and then again in 1146 to Zengi’s son Nur ad-Din. He was later taken prisoner by Nur ad-Din in 1150, and was held in Aleppo, where he was blinded. Meanwhile, Agnes was already married, while she was still a teenager, to Raynald of Marash, who was killed in battle in 1149.
We don’t really know why she ended up coming south to Jerusalem, but she was presumably looking for someone to support her now that she was a widow and her father was gone (he was still alive at this point, but eventually died in prison in Aleppo in 1159). Apparently, she found a good match in Amalric. No source specifically says “they fell in love and decided to get married”, but…whenever two medieval nobles get married for reasons that don’t seem to make any political sense, that’s probably what happened!
Unfortunately they were too closely related, according to the church’s rules against consanguinity. Amalric was the second son of Queen Melisende and her husband Fulk of Anjou. Melisende was the daughter of one of the original crusaders, King Baldwin II, and his Armenian wife, Morphia of Melitene. Baldwin II was a relative of the first two kings, Godfrey of Bouillon and his brother Baldwin I (although how exactly they were related is not quite clear), but more importantly, Baldwin II was the son of Hugh of Rethel and Melisende of Montlhéry. On Agnes’ side, her father Joscelin II was the son of Joscelin I of Edessa, who was the son of Joscelin of Courtenay and Elizabeth of Montlhéry. Elizabeth and Melisende of Montlhéry were the daughters of Guy I of Montlhéry, a small barony south of Paris.
In other words, Agnes and Amalric shared a great-great-grandfather. Spouses were not supposed to be related within “7 degrees” - i.e. if they were sixth cousins or closer. That made it virtually impossible for European aristocrats to find anyone to marry, since they were all related within the prohibited degrees! It was eventually changed in 1215 to 4 degrees, which made things a bit easier (although Agnes and Amalric still would have been too closely related).
Of course, most people ignored this anyway, and only dealt with it later if it ever caused problems. European marriages at the time were often technically against the rules, but the church could also grant special permission to marry (a dispensation). Amalric and Agnes didn’t ask for one, and apparently Fulk, the Latin Patriarch of Jerusalem, objected to their marriage, but no one else cared and they were allowed to marry anyway, in 1157. Amalric’s brother King Baldwin III was still alive at the time, and Amalric wasn’t expected to become king, so why worry about it?
The Lignagnes version says that Agnes came south to marry another crusader noble, Hugh of Ibelin, and Patriarch Fulk objected to her marriage to Amalric because she was already engaged to Hugh. Ignoring the rules of consanguinity was one thing, but it seems pretty unlikely that anyone would have accepted the marriage if Amalric had literally kidnapped Agnes and forced her to marry him. At least, none of the contemporary 12th-century sources (from the crusader states or from Europe) mention that, even though it would have been extremely scandalous if true.
Agnes and Amalric had two children, Sibyl and Baldwin. King Baldwin III died unexpectedly in 1162, without children, and was succeeded by Amalric. But now the church and the nobles of Jerusalem decided that Amalric couldn’t become king if he was still married to Agnes, so the marriage was annulled, i.e. legally speaking it never existed. However, their children were confirmed as legitimate. Their son Baldwin later succeeded Amalric as Baldwin IV, but he was a leper and died without children; Sibylla succeeded him as queen.
Amalric eventually married the Byzantine princess Maria Komnene, and Agnes remarried as well - to Hugh of Ibelin. That’s probably where the Lignages account is confused; she did marry Hugh eventually, but only after the annulment of her marriage to Amalric. Hugh died a few years later in 1169, and Agnes married her final husband, Reginald of Sidon.
Historians still find it strange that the marriage had to be annulled before Amalric could become king. The church could have easily granted a dispensation. Why didn’t they? There must have been political reasons. Some sources imply that Agnes had poor morals somehow, as if she was having affairs with other men while married to Amalric, but those sources are also much later from the 13th century. But maybe those rumours were circulating in the 12th century too.
Politically, it’s possible that there was an “Angevin” faction in the royal court, descended from the Angevin barons who had arrived when Fulk of Anjou married Melisende. There is evidence that the new Angevin barons had displaced the previous generation of “Norman” barons in the kingdom. Now, a generation later in the 1150s and 1160s, maybe the Angevins were suspicious of the influence of the Courtenay family, especially now that Agnes’ Courtenay relative Elizabeth of Courtenay had married Peter, the son of Louis VI of France. Peter was the brother of Louis VII, who had just shown up on the Second Crusade a few years earlier in 1148. Maybe they were worried about French royal influence. That branch of the Courtenays ended up becoming very powerful - they ruled the Latin Empire in Constantinople when the Fourth Crusade conquered the Byzantine Empire in the 13th century.
When Amalric died in 1174, Agnes had a major influence during the reign of her son Baldwin IV. Among other things she ensured that her friend Heraclius was appointed as Archbishop of Caesarea, and she appointed her brother Joscelin (commonly called Joscelin III, as if he was still in charge of long-lost Edessa) as seneschal, a high-ranking position in the kingdom. Joscelin became one of the wealthiest and most powerful nobles in Jerusalem, so maybe this is what the church and the nobility of Jerusalem were afraid of back in 1163 - Agnes would be too powerful and show too much favour to her friends and family if she was queen. Heraclius eventually became Patriarch of Jerusalem, instead of the other candidate, William, the archbishop of Tyre. William of Tyre’s chronicle is our major source for these events, and his skewed, anti-Agnes perspective has always affected our understanding of the period.
So, the short answer is, Agnes was in Jerusalem because she was a widow and her father was a prisoner of war; Amalric was the Count of Jaffa but he wasn't originally the heir of the kingdom, his brother was the king. Amalric was described as good-looking in his youth and a bit of a womanizer, so he probably could have married anyone, and Agnes could have too. But presumably, they simply fell in love. Agnes certainly wasn't without political value, and if anything, she had too much power and ambition, which was part of the reason they were forced apart.
Sources - the work of Bernard Hamilton is essential here, he basically spent his whole career trying to untangle the biases of William of Tyre and other medieval sources:
Bernard Hamilton, "Women in the crusader states: the queens of Jerusalem", in Medieval Women, ed. Derek Baker (Ecclesiastical History Society, 1978)
Bernard Hamilton, “The titular nobility of the Latin East: the case of Agnes of Courtenay”, in Crusade and Settlement (University College Cardiff Press, 1985)
Bernard Hamilton, The Leper King and his Heirs: Baldwin IV and the Crusader Kingdom of Jerusalem (Cambridge University Press, 2000)