International context is important, Egypt had already evicted all of its resident Soviets a few years earlier, which was a diplomatic humiliation for Moscow. However they had no real leverage to retaliate against the Egyptians (and since Israel only took arms from the US, there was no point in trying to support them during the 73’ war to spite Egypt). When Somalia also evicted all of the Soviets a few years later, it opened the old wounds of the Egyptian eviction, they considered it a blow to Soviet prestige and superpower status.
The difference here is that the Soviets did have a willing ally in Mengistu in this situation to exact revenge, so Moscow first airlifted a gigantic amount of military hardware, but then realised Somalia had utterly annihilated the Ethiopian army, with nobody capable of operating tanks and armoured vehicles, so they airlifted tens of thousands of Cubans, Yemenis and Libyans, and all of the operations were led by Soviet generals. This was done to sent a message not just to Somalia but to any partner of the Soviet Union that had ideas of leaving or cutting ties with the Warsaw Pact.
If there had been no eviction, then the Ogaden would have remained in Somali hands for years to come, and with the Reagan administration taking office, those gains could have been permanently consolidated. Barre instead made an irrational decision without actual assurances in writing from the Carter administration that they would back him, and what is worse is the fact that the latter admin even blocked Iran, Egypt, Saudi and Iraq from replenishing the Somali Army with US hardware during the War.
One thing is for sure, the civilian administrations knew exactly what they were doing when they remained ‘non-aligned’ by keeping the superpowers at a safe distance. Play with fire and you will eventually get burned.