Also... scrapping an improvement and adding a farm once your pop is maxed is ultimately more productive than most basic improvements.
No, it's not. It depends on what the multipliers and base production are and can be, which depends on empire bonuses, local starbase bonuses, planet bonuses, planet tile count, planet tile configuration, the improvements you have, which improvements you use, how you cluster them, etc. The optimal build for any given planet balances farms and factories (or, more accurately, base production and output multipliers), it isn't simply "maximize this and ignore that."
Simple example: Let's say I have a planet with 50 production and +100% manufacturing, and I can replace a factory with a farm to change the production to 60 and the manufacturing bonus to +75%. Assuming 100% of output is in manufacturing, making that change would increase my output from 100 manufacturing to 105 manufacturing. What happens when I remove another factory and reduce the manufacturing multiplier to +50% but increase the base production to 70? My output goes from 105 manufacturing to 105 manufacturing*. What if I drop another factory (thus dropping to +25% manufacturing) in favor of another farm that (eventually) gives an additional 10 production? My output drops from 105 manufacturing to 100 manufacturing. There is clearly a balance to be struck between output multiplier structures and base production structures.
*Since by this point in the example there is no long-term increase in output by replacing a factory with a farm, replacing that factory with a farm is in fact worse than leaving the factory in place, as the world will see an immediate drop in output due to the destruction of the factory and will not exceed its previous output even after the population has reached the new cap. It can also be the case that replacing the first factory wasn't a great decision, either, because there is a number of turns T such that for N < T turns after the destruction of the factory you would have had more total output from the planet by keeping the factory than by replacing it with a farm, and if T is too large then the alteration won't pay dividends soon enough to have been worthwhile. (E.g. if replacing my factory with a farm will only break even a thousand turns from the time I make the change, is it really worth it? How likely is it that I'd still be playing, or that even if I was still playing that the game would go on long enough afterwards for the payoff to actually matter?)
Now, granted, there are enough empire-wide output bonuses, particularly if playing with relics, that it can frequently be the case that the optimal configuration for a planet is to only build farms on said planet, but such is not always the case. The approval and coercion mechanics make the output maximization problem harder as well; approval because it's theoretically possible to need more morale bonuses than you get from the techs, nearby economic starbases, relics, etc and so you might need to compare a build with morale structures to one without (though with the approval production modifier curve being what it is in 1.5, it's very rarely the case that you'd ever want an approval structure instead of a farm or factory), and coercion because the mechanic theoretically makes it possible for a mixed-output world to be superior to a single-output world in terms of total output (which means that if you're looking to maximize total output rather than a specific output, you need to maximize the three-output equation rather than the single-output equation, and that's a much more difficult problem; you may need to go to a two- or three-output solution anyways since the coercion mechanic makes it possible for a given output type to be maximized at some point before 100% of production is dedicated to that output type), and then there's the issue with coercion acting on output again through a poorly-rationalized approval penalty.