Put it this way:
We like our air to be mixed around well. Mixing the air prevents uneven concentration buildup of not just pollutants (smoke, ozone, chemicals, etc), but also fog (which is pooling of cool and moist air), smells, even sounds (that's why you can often hear distant traffic more near dawn).
There are two places that air near the ground can go: up or out.
Warmer air rises. When an inversion sets up, it's a layer of warmer air aloft that thereby blocks air below from being able to rise anymore.
Most nights there are inversions since the ground cools more quickly than the air higher up. But usually during the day, sunlight heating the ground starts the air rising and mixing around. And viola, no more unpleasant buildups!
But additionally, inversions also are formed when cold air is blown in near ground level, such as during a cold front. But, the peak of such a cold airmass generally associates with high pressure.
And high pressure cores have calmer horizontal winds.
So when such a cold high pressure gets stuck and parks in place, it can lead to prolonged inversions.
Additionally, inversions tend to be self-perpetuating over time. Fog and smoke form, block out the sun, and those just keep the low-level air layer cold.
It can be very difficult to forecast just how much the inversion will break down during the day, leading to greatly busted forecasts. I remember many times in Oklahoma where they thought it would warm up a fairly typical 20 degrees (F) during the day, but the fog never fully eroded, and we only ended up rising a few degrees.
We also ended up having solid weeks or more of foggy conditions.
Furthermore, the geography in some regions favors inversion formation, and so inversion forecasting inversions can be particularly important for such locations. Sometimes these features can even enhance storm systems or alter their tracks. For more on these targets, look into cold air damming and marine layers.
Inversion conditions also can prove to be quite important flies-in-the-ointment for severe storm forecasting as well. Severe thunderstorms often rely quite a lot on afternoon heating to fuel the rapid updrafts of the storms. Sometimes the same mugginess that highlights that conditions are ripe for storms can wind up being so rich that fog and low-level clouds develop overnight, and prove resilient well into the day. The result can be that the forecast severe weather outbreaks ends up coming to nothing. Or instead, if a fog inversion were expected but doesn't materialize it can often generate unexpected or incorrectly timed severe weather outbreaks. So severe weather forecasters have significant interest in understanding inversions as well.
So... inversions form most every day, but typically as the day evolves, the atmospheric heating engine kicks in, and wind resets the atmosphere towards being more homogeneous. But when stronger inversions build in, they can snowball into much more depressing, and even very dangerous conditions.