Governments have limited resources and so they’ll focus and optimize their spending to maximize efficiency and the same reason a bus route would be unattractive to a for profit operator would likely force a non for profit one to direct their attention somewhere else.
The best way is usually forcing the for profit operators to bid on whole regions rather than individual routes and mandating minimum service levels across the board which would prevent operators from running a bus once a day and calling it a served route.
The only way in which a government run transportation provider would not experience this issue is if the people are aware of it and are willing to pay the extra money in taxes to cover the costs of running unprofitable routes and would actively lobby their governments to spend that extra money on exactly that which isn’t likely.