Can I exchange the CPU of my Acer Nitro 5 (socket: am4) for a desktop CPU with the same socket? And is it bad if the CPU is not well ventilated?
No do not go. The notebook CPUs are often also soldered.
Apart from that, a desktop CPU consumes a lot more power (you can't set anything in the notebook's BIOS) and therefore has a higher waste heat. A notebook does not manage this in terms of cooling performance and the power requirements can hardly be covered.
Swap notebook CPU for desktop CPU?
No is not possible.
Even if both CPU models were socketed (most of them are soldered in the NB) there would be differences and therefore both would not fit.
In most laptops, the CPUs are not socketed, but soldered. From what I saw, the laptop Ryzen CPUs are used in the Nitro 5, which are just soldered.
There are very few laptops that have socketed CPUs, and these are usually such 3-5 centimeter thick monsters as the Alienware Area51m. But the Nitro 5 seems to be a normal laptop, so that's almost certainly not the case here.
And yes, inadequate cooling is of course a problem. A stronger CPU would run the risk of overheating and would have to throttle performance to prevent this. This could result in poorer performance than with a somewhat weaker, but cooler CPU.
That's why the Alienware Area51m is so fat, because the desktop CPUs installed there need a lot of cooling.