They came up with what they thought was a reasonable theory. It is just one theory to explain it, there are other possibilities. The key is that they make theories that are consistent with the observable universe, and if they end up being unprovable by experiments or observations, then they are discarded, and then scientists go back to the great question, Why? You can see this with string theory, a lot of it is mathematically sound, but there is no actual observable evidence of it, so quite a few scientists now just regard it as unprovable nonsense. They may well regard dark matter/energy as nonsense if evidence continues to fall short. That is the whole point of science, observe something, come up with ideas for "Why?", and then test them. If they fail to explain it, then the theory is eventually discarded, and new ones must be made.
And that is exactly how science differs from religion. Religion is set in stone, there is only one true word of god, the bible. The mere text of it is considered divine and straight from god, written with the influence of the holy spirit. It is infallible, it cannot be questioned, and when it is proven wrong, or parts of it continue to fail the evidence test, the religious simply say "You need to have faith". There is no furthering of knowledge with religion, it is essentially a dead end that has already been decided.