From a purely economic perspective, it doesn't make sense to feel resentful when a national company is sold to foreigners. Imagine a company in my country is sold to a German investor. This shouldn't be a problem, as from the sale price my country could go to Germany and buy a German company instead. So it's all fair game.
However, some countries are growing in influence relative to others. For example, China is growing in influence and economic power relative to the rest of the world. When Chinese companies buy European companies, this is a very obvious sign of that growing influence and this is one reason it raises concerns in the countries that are being targeted. It is hard to accept that one's country might be losing in relative influence.
From a strategic point of view, it might make sense to try and protect national companies from foreign buyers. If the Chinese buy a German company, they might get access to new technology, which can help them develop their own industries. This can lead to increased competition for the German industry. By protecting national companies and proprietary technologies, Germany can limit competition and stay more competitive on the world stage.
The above discussion covers the buying and selling of existing assets, which is usually more controversial. Foreign investment in greenfield projects (when a foreign company builds a completely new factory) is generally considered positive for the national economy as it creates jobs and generates additional tax revenue for the government.