What is the difference between a loan and an investment? IMF, WB, ADB, IDB, AIIB are known to give loans. On the other hand, China is said to be investing in Pakistani project termed as CPEC.

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.