Most historical sources seem to agree that the Byzantine Empire were doomed by the sacking of Constantinople in the Fourth Crusade, but the actual empire didn't fall for another 250 years, what is it that kept them alive for so long after that?
Now I know it's not quite that simple, the Byzantines were actually doing quite well at the end of the 13th and start of the 14th century with the Byzantine-Mongol Alliance (by the way, if anyone wants to explain why the hell the Mongols would agree to something like this it would be greatly appreciated) and the reconquest of territories in Anatolia helped the empire tremendously. But the Empire lost Nicaea in 1331, which is less than 180km (~110 miles) from Constantinople, Macedonia fell to the Ottomans in 1371 and the Byzantines then lost their last piece of Anatolian territory in 1390.
According to this by 1400, the Byzantine Empire was nothing but Constantinople and a few small pieces of land, the city itself was a ghost town, and they were surrounded on all sides by the Ottoman Empire. It seems to me that Constantinople would be a very desirable place to hold, so why didn't the Ottomans just sweep in and take the rest of the Byzantine territory in 1400 after they'd already renounced their vassalage?
As we're talking about a time span of two and a half centuries there were several factors in place working in favor of Byzantine survival that aren't necessarily interelated. Some are strenghts the empire could almost always count on. For once Constantinople is just very hard to take by force. Many would be conquerors (in this timeframe for example the Bulgarians) were stoped by the impressive defensive structures of the city. On the other hand Byzantine diplomacy could still be quite potent. The most dangerous threat right after the reconquest of Constantinople in 1261, the kingdom of Naples under Charles of Anjou, could be neutralized by supporting rebels on the isle of Sicily and encouraging the royal house of Aragon to enforce their own claims to the island. The Byzantine Empire could still be a valuable ally for foreign powers because of the strategic position of its capital. The Mongols of the Golden Horde for example needed to go through the Bosporus to reach the Mamluks of Egypt, with whom they shared their rivalry with the Ilkhans of Persia. The Mamluks in turn needed access to the South Russian Steppes to purchase slave soldiers for their armies.
Furthermore for the first one and a half centuries after the conquest of Constantinople by the Crusaders there simply was no power in Anatolia or the Balkans that could consistently threaten Byzantine survival. The Latins themselves weren't able to build a strong Empire. They would have needed continued support by the Venetians but those weren't realy interested in a powerful Crusader state that could potentially threaten their trade like the Byzantines had done. The West failed to substantially support the Latin Empire that never had been the goal of the Crusade in the first place. The two most powerful foreign powers in the Balkans were the Bulgars and the Serbs. Both had ambitions to replace Byzantium by their own version of a greco-slavic empire. But both depended heavily on a strong leader on the throne. In case they lacked one their empires fragmented quite rapidly. This happened more than once in Bulgaria and in Serbia right after the death of emperor Stephen Dušan in 1355. In addition Bulgaria was raided frequently by the Mongols beginning in the 1240s. In Anatolia the Seljuqs of Konya prospered at first because of Byzantine weakness and reached the hight of their power in the first half of the 13th century. But after their defeat at the hands of the Mongols at the battle of Köse Dag in 1243 they were pretty much done for and began to fall apart into smaller emirates. So it seems the Byzantines benefited from being just out of range of the Mongol attacks while many of their rivals were subjected to them.
This all changed in the course of the 14th century. The Ottomans were able to build a stable and powerfull empire where others had failed. At first they benefited from internal divisions in the Byzantine Empire but already under Murad I. they were much stronger than the Byzantines and could make them their vassals. Like you said Constantinople was a very desirable place to hold for the Sultans and could sometimes be a thorn in their side because of its strategic position between both halves of their empire. Sultan Bayezid I. also saw this and so he tried to conquer the city already in the 1390s. But the city walls and a crusader army delayed his success. Then in 1402 the rise of the Ottoman Empire was set back quite severely. The turko-mongolish warlord Tamerlane defeated Bayezid decisively in the battle of Ankara and took him captive. Several Ottoman vassals were set free and the sons of Bayezid began fighting each other for control of the sultanate. In 1413 Mehmed I. emerged victorious from this struggle. And he did so with Byzantine support so the relations between the two states were much better under his reign. In 1421 his successor Murad II. again besieged Constantinople but had to abandon the effort because of a revolt in Anatolia (the Byzantines seemed to have had a hand in that). Only in 1453 the Ottomans under Mehmed II. were finally successful.
So right until the end the walls of Constantinople and Byzantine diplomacy proved to be the most valuable defence of the empire. On the other hand the Ottoman crisis after the battle of Ankara was beyond the control of the emperors and may very well have extended the life of the Byzantine Empire by half a century.