It's more about investors buying long-term bonds than selling short-term ones. The shortest-term rates are controlled by government central banks, in an attempt to manage the economy. They typically reduce short-term rates in a recession.
But if a recession is forecast, long-term rates drop sooner, because investors expect short-term rates to drop. Another way to view it is that investors buy long-term bonds to "lock in" their yield, fearing that if they don't do so, the available rates (and thus returns) will be lower in the future.
Sometimes a recession is associated with increasing short-term rates, but that tends to be a matter of the central bank's hiking action causing a recession rather than responding to it. This can happen when the central bank is concerned about inflation, and is willing to risk a recession to get it under control.
The general cycle of events would be: long-term rates up (inflation expectations) -> short-term rates up (prevent overheating) -> long-term rates down (recession expectations; this is the point where the yield curve is inverted) -> short-term rates down (fight the recession) -> long-term rates up...