Why are people and dolphins the only mammals that have sex for pleasure?
Your question gets at the heart of what many cognitive scientists in the fields of neuroscience, philosophy, and computer science are trying to address. This great mystery in science is consciousness. In particular, your question is related to the mind-body problem. The issue here is what, if any, neural states in our physical brain lead us to have subjective experiences in our mind, which are called qualia by many people in the field of cognitive science.
Besides humans and dolphins, other mammals such as certain monkeys have sex too. Sex usually leads to euphoric pleasures that are related to the release of certain neurotransmitters in our brains. These neurotransmitters help us relax and make us feel good.
The mammals you mention all have neocortex, which is associated with higher levels of consciousness. For example, ants do not have neocortex. Higher levels of consciousness probably lead us to do certain things for the simple pleasures, such as art, food, and sex.
Most animals have sex purely for the purpose of reproduction. The claim that dolphins have sex for pleasure is true for a very specific definition of "sex for pleasure," which is copulation between the male and female of a species not for the purpose of reproduction. Most animals cannot afford to waste the energy that is put into the sexual act unless it leads to the production of offspring. For most animals, it seems that there is no biological advantage in engaging in sex when there is no possibility that their genes will be passed through the production of offspring. Therefore, females of most animal species give off detectable signals when they are fertile: a change in appearance, a distinctive smell, specific sounds or behaviors to signal to their partner that they are fertile. If fact, most females will push their mate away or ignore him when they are not fertile.
Humans, bonobos (also known as Pygmy chimpanzees) and dolphins are a bit different in this aspect. They are all intelligent social animals, whose cooperative behavior proves to be more successful than that of the individual alone. It is probable that in these animals, the use of sex evolved beyond reproduction to serve additional social functions. It can keep the male around the female and offspring, thus helping tend for the offspring. Sex reinforces intimate social bonds that can form larger social structures, something that may help in overall survival, group hunting, defending against intruders and so on.
But there is a difference between humans and animal in this aspect though. Animals other than humans have no awareness that their sexual activities are connected with reproduction: They engage in sex because they're biologically driven to do so, and if the fulfillment of their urges produces a physical sensation we might "pleasure," it isn't the least bit affected by the possibility (or impossibility) of producing offspring.