What is the difference between these two terms in these two particular cases?
A loan is an agent lending funds to another agent. This money can be used for investment spending, or it can be used for personal consumption expenditures. It can be used to buy fixed assets like real estate, which may or may not be "investment" depending on how you use the terminology. In the case of the IMF, the role of the institution is to ensure financial stability by providing funds to countries in an emergency; for example, a country which becomes insolvent and is unable to service its sovereign debt is likely to seek help from the IMF. The IMF would then provide a bailout loan along with a stabilization program aimed at improving the country's public finances. This is not investment, in the sense that it does not grow the country's capital stock; it just allows it to meet its obligations to past creditors.
Investment is an expenditure which will yield revenue in the future, and hopefully amortize itself through that revenue. In the case of a household, investment can take the form of acquiring financial assets; in the case of an economy, investment often refers to actions which improve the country's productivity. This can be the construction of new factories, higher wages at state subsidized education institutions, higher research and development spending by the private sector, etc.
The reason the two are related is that quite a lot of investment is done through borrowing. A corporation can borrow to ramp up capital expenditures, a country can borrow on international capital markets to invest more in infrastructure, an individual can take out a mortgage to acquire a house. All of these can be legitimately described as "investment".
China is said to be investing in Pakistan (and quite a lot of other countries) under its Belt and Road Initiative because of two reasons: these expenditures are aimed at boosting domestic productivity in those countries, and China expects to reap benefits from its program. The potential benefits for China are plentiful. China is still very much an export-oriented economy and a global manufacturing hub. Strong growth in underdeveloped countries is likely to increase demand for Chinese goods, allowing the Chinese economy to experience faster growth. China also hopes to get direct revenue from its investment operations under this program, and they have the additional goal of expanding their political clout. Contrast this with the case of the IMF, whose founding goal is to ensure financial stability and to prevent crisis contagion and panic. The two forms of lending are evidently quite different in their desired goals.
Multilateral, international organisations like all the ones you mention do not "invest" in countries. They provide "support" in the form of technical and financial assistance. For example, the World Bank offers financing instruments like:
Investment Project Financing provides IBRD loan, IDA credit/grant and guarantee financing to governments for activities that create the physical/social infrastructure necessary to reduce poverty and create sustainable development.
Development Policy Financing provides IBRD loan, IDA credit/grant and guarantee budget support to governments or a political subdivision for a program of policy and institutional actions to help achieve sustainable, shared growth and poverty reduction.
Conversely, China is a country, with a particular set of geopolitical goals, and which is interested (one guesses) in the wellbeing of their citizens. As such, the Chinese government uses institutions like the Exim Bank to provide loans to countries abroad where the Chinese government expects rewards. China is investing everywhere, Africa, Latin America, Asia. Some have even accused them of "neo-colonialism".