Most likely because they have complex tentacles that need fine motor control. Their brains developed to control their body. Their eyes seem to be good as well.
Even in human brain huge area of brain dedicated into hands. Human fine motor skill (or dexterity) is superior compared to other apes. We can do small detailed moves. Other apes and monkeys are clumsy.
After the complexity of brain developed to control their dexterity, octopus gets benefit from spatiotemporal intelligence to exploit tentacles in hunting and moving. It's not surprising that intelligence plan and solve problems as well.
I guess that's it. Some other asocial animals are pretty smart, because they need it for hunting, or something. (Although even the most anti-social mammals still interact with their mom!)
The marginal intelligence point makes survival to reproduce more likely, so octopi that are marginally smarter tend to be slightly more likely to reproduce.
However, they seem to die very soon after mating for some reason related to their evolutionary history. There's no way for a marginally longer-lived octopus to be more successful at reproduction, because reproduction is a one-shot event for them. If anything there's pressure to reproduce (and die) at a younger age, since these octopi would be more successful.
Such are the tragedies of evolution, the blind idiot god.
They live in complex environments. Often on the boundary between water and land. And some octopuses, do seem to make good use their intelligence - for example the mimic octopus.
I guess an important thing is that they hunt in this environment (in which clams also do just fine). And, like us, they don't have much bodily defence against being eaten by others.