But in this case, political history is the best and probably only way to categorize defunct countries. Yugoslavia was the successor to the Kingdom of Serbia after WW1. They gained territories with ethnic Croats, Slovenians etc. and they changed the name of the country. There was no official country of Croatia, Slovenia etc. before the 90s. All medals won by Croats, Slovenians were won, when they were part of an established historical country, whether it was Austria-Hungary or Yugoslavia.
" The Olympic Committee of Serbia, created in 1910 and recognized in 1912, is deemed the direct successor to both Yugoslav Olympic Committee and the Olympic Committee of Serbia and Montenegro by IOC, and therefore the inheritor to all the records of the defunct nations."
http://oks.org.rs/istorija-olimpijskog-komiteta-srbije/?lang=sr-latn
"Both FIFA and UEFA consider the Serbian national team to be the direct and sole successor of the Yugoslavia and Serbia and Montenegro teams."
https://www.uefa.com/insideuefa/member-associations/association=srb/
Let's say in 10 years Bavaria wants to split from Germany and be it's own country. Will all the medals won by current Bavarian athletes stop counting toward Germany's overall record. Of course not. Those medals were won, when they were part of the country Germany. When Bavaria splits, they become their own country, without any inheritance, because their former political state still exists. They start from scratch.
It is the same for Croatia, Slovenia, Bosnia etc.They were provinces, which gained independence and started from scratch. They can't have any claims to former records, because they broke from Yugoslavia, and what was left continued again as Serbia.
The same thesis should be applied to the Soviet Union and Russia. The republics were all part from the Russian Empire up to the end of WW1. The West tried to dismantle the Empire, but the Republics combined again (bar the Baltic States) almost instantly, but this time it was called the Soviet Union. Ukraine, Belarus, etc. never competed separately until the 90s. at the Olympics. Russia is considered a legal successor of the Soviet Union, while the rest started writing history as new nations.