Any good science advance can be done only incrementally over previous advances done by others.
Those who are smart enough to contribute to science advances are also aware that their work would have been impossible if others would not have published the results of their work, instead of keeping those for themselves.
Therefore they understand that the best strategy for being able to do further advances is to publish what they have found until now, so that in the future, after receiving new results from others, they will be able to discover new advances.
This is a rational optimal strategy that does not need any supplementary incentives, like being paid for publications or believing in science or whatever.
Of course there are always people who believe that they can cheat in this game and keep secret some useful discoveries.
However, in this case cheating works only if you get out of the game, i.e. if you believe that you have made a discovery so great and definitive that not only keeping it secret can bring profits but also that it no longer needs any improvements, so you will never need to do research again in that field.
You might get some short-term profits by secrecy, but it is quite certain that you will not be able to find any improvements at the same pace as when the discovery would have been published and you would have seen feedback from others trying to use it and enhance it.
The great advances in sciences and technology in the second half of the second millennium were due precisely to the European obsession for quickly publishing any novelty, while China and other Asian countries dominated by Chinese culture stagnated, due to the obsession for secrecy, e.g. that every wise master should reveal his whole knowledge only to a few trusted disciples, possibly only to a single one chosen from them and possibly just at the latest moment possible, on the death bed.
Unfortunately, in the last few decades there was a continuous shift from traditions to publish everything in order to ensure the fastest progress to policies to keep secret as much details as possible, due to what I consider as a false belief, that this secrecy creates a competitive advantage.