In the 12th century, Cyprus was a Byzantine province. It benefitted from the presence of the crusader states , since crusaders could now stop there on their way to the mainland, and there were probably communities of Italian merchants there, as there were elsewhere in the Byzantine Empire and the crusader territories. In 1176 the Byzantines lost of control of much of Anatolia when they were defeated by the Seljuk Turks at the Battle of Myriokephalon, so Cyprus fell out of Constantinople’s sphere of influence, although it was still officially a province. In 1184, a member of the royal family, Isaac Komnenos, was either appointed governor and then rebelled against Constantinople, or he simply took it over (it's not entirely clear how it happened).
Meanwhile, the crusader states on the mainland collapsed when Saladin invaded in 1187. They lost Jerusalem and almost all of the other crusader-held territories, and the Third Crusade was launched in response. On his way to the Near East in May 1191, Richard I of England's fleet ran into a storm and some of his ships were shipwrecked on Cyprus. According to Richard, Isaac Komnenos robbed the ships and the survivors of the wrecks, and he tried to take members of Richard's family hostage. When Richard arrived he defeated Isaac in a small battle, took Isaac prisoner, and occupied the whole island.
Richard left for the mainland in June 1191, where he helped capture Acre and eventually some of the crusader Kingdom of Jerusalem was restored. He left two of his own men in charge of governing Cyprus, but
“The king’s arrangements proved short-lived. Within a few weeks of his departure and before the fall of Acre, Richard sold his rights in the island to the Templars. A period of Templar domination then ensued, lasting until April 1192. It was rapacious and unpopular, and the Order sent insufficient troops to keep the populace under control. On April 4, the day before Easter Sunday, the Cypriots in Nicosia attempted to rise and massacre the garrison. The small force of Templars in the town made a sally and cut down a substantial number of the insurgents. Although this incident might have appeared as a victory, the master evidently decided that Cyprus was more than the resources at his Order's disposal could manage and surrendered the island to Richard. Richard promptly sold it again, this time to Guy of Lusignan, on terms similar to those by which the Templars had held it. (Edbury, 7-8)
The Lusignan dynasty continued to rule Cyprus for about 300 years, followed by the Venetians, then finally the Ottomans in the 16th century. Out of all this time, the Templars only controlled it for less than one year.
So, in brief, they got it because Richard the Lionheart sort of conquered it by accent, but he didn’t really want it. He was looking for someone to buy it from him, and the Templars apparently thought that was a good idea. But they were pretty ineffective governors, and they didn’t really want it either, so they sold it back to Richard, who then sold it to the disgraced former king of Jerusalem, Guy of Lusignan.
Source: Peter W. Edbury, The Kingdom of Cyprus and the Crusades, 1191-1374 (Cambridge University Press, 1993)