Because there is no way to know the true solution, everyone is just guessing so in the end it is random chance that determines who gets to mine a block, but those who spent more effort have proportionally more chance to win.
Imaging a million haystacks with a million different keys scattered within them. There is a lock which only one of those keys can open; it is difficult to find the key, but when you do, anyone can easily verify it is correct by turning it in the lock. Once a key has been found, a new lock is created and the process starts again.
The more robots (mining power) you have to search for the key, the more likely it is that you will find it before competing machines do.