Engineering is the art of compromise. You usually have to juggle with several parameters, some of which may be at least partially contradictory.
For instance, you could have to find the best compromise between:
- battery life
- heat dissipation
- networking requirements
- UI and ease of use
- ease of development
A microcontroller will usually be good for size, cost, battery life. It may be limited in terms of speed or precision, networking, UI, and ease of development.
At the other end, a full grown computer will be good for speed, networking, UI and ease of development, but will be quite bad for size, cost, battery life, heat dissipation, etc.
Of course the limit is quite blurry, with chips such as an ESP32 being a bit in the middle, as are many chips based on ARM M cores.
For each project, you should start by listing your requirements. Many will outright eliminate one or the other. If they eliminate both, then you know you may need both, to play different roles, eventually in different places or at different times (for instance a small low power micro controller in a remote battery powered sensor, and a more powerful CPU on mains power to process that data). That’s often where cloud-backed systems come into play, but not always.
Or it just may not be doable at all at the present time: if you need a sub-$1 chip to perform very computing intensive work on battery with a 5-year lifetime, this may not be possible until new chips come on the market (if at all).
If both fit the bill, then you weigh the pros and cons of each, which may be dependent on your specific circumstances: being able to reuse code or knowledge or existing tools and systems may play in favour of one or the other.
The most sensitive parameter is often power. If your need to run on battery with a significant lifetime (months or years, not hours or days), you can just forget about an RPi.