Turkey did not join the Axis for many of the same reasons Spain did not. Turkey was in no condition to fight any significant war with anybody, their infrastructure was poor, and the Axis had little ability to supply the things Turkey needed in peacetime, let alone in wartime, to replace what the loss of trade with the UK/US would remove. Given their neighbor to the north, unless and until the collapse of the USSR had occurred or was seen by the Turks as inevitable, joining the Axis invited retaliation from the USSR which would have loved to seize Istanbul and parts of eastern Anatolia.
The Hungarians were in a different situation, their country was almost completely surrounded by the Reich or Reich controlled territory and their territory was a supply conduit for Romanian oil among other things. They tried, unsuccessfully, to dance around the Allied coalition by basically only fighting Russia, but that did not last.