However, coming from Istanbul a direct bus (or a bus from Sofia) might be worth considering since there is no direct train connection.
Have a look at the map here: rail.cc/en/train-ticket-railmap-of-europe
By train, you have to travel by overnight train (attention, bus replacement service in operation rail.cc/de/tuerkei/xtr
to Sofia, then again by overnight train in direction of Beograd. Change in Nis for the train to Skopje.