I am not sure about countries but I know that many persons and businesses prefer to use borrowed money because loans are cheap and many prefer loans to spending/investing their own money. I believe it's the same with countries. Instead of raising taxes, raising retirement age and other unpopular measures, why not just borrow some money if it's easily available?
some countries prefer loans than using their own money due to the fear of unforeseen circumstances. so for that, they will decide to borrow money that they will be using so as not to leave their foreign reserve empty in case of emergency issues. For instance, emergency issues like COVID-19 that happened in 2019 to 2020 when almost everywhere in the world knows about. And also sudden war between Ukraine and Russia require funds for a particular country to survive, even the economy of the country will be unstable due to lack of peace and harmony.
During this time, everyone knows about the curfews and lock downs in the affected areas which will hinder their day to day activities and will lead them to go into borrowing.
Borrowing money from world bank is averagely done when the country wants to maybe take on a large project which requires more money than they have. Imagine you have $50 but you want to do something and need extra $50, then you have to borrow the money from your friend. People who doesn’t know much about you and your friend’s agreement would think that you borrow $50 which they know you can afford, whereas you added it to what you have so you can solve your problem. It can also be because the country doesn’t want to run into financial issues so they would rather use borrowed money than the one they have.
Yes, exactly they are a lot of countries that borrow money to help them complete their uncompleted projects and pay them back with interests.
Some even borrow money to start and complete their projects with the agreement that they will pay them from the revenue generated from this project, and when payment is completely made, then, they will stop the payment. And by so doing, they will not have to use their own money and everything will be moving fine.
But this one which country has to take loans and use one of their main source of income as collateral, to me, this type is a very dangerous one which need to be review.