In our primate relatives, there are many reasons why homosexual behavior exists and is maintained.
In some species it is related to general sexual expressiveness. Japanese female macaques form sexual courtships and they aren’t picky about individuals. However, when they desire sex, they can be very pushy about desiring it. They will sometimes mount males in addition to forming courtships with and mounting other females. This increased sex drive means that they are more likely to produce offspring because, even if they spend a few courtships with other females, they’ll (usually) end up in courtships with males too. Female-female sexual relationships tend to follow the same evolutionary patterns that male-female sexual relationships do, as in, they avoid incestuous pairing. Since the female-female sexuality has no negative impact on overall female fertility, there is no reason for this high level of overall sexuality to be reduced.
Capuchin monkeys (who are thought to be similar to us in terms of their social evolution) also have a high sex drive which sometimes leads to same-sex pairings. However, they also use male-male sexual behavior as a way to form male bonds. Males form sexual relationships with each other as a way to promote brotherhood and express affection. Males will also make up after fights with sex. The use of sex to form bonds is such that individuals will behave aggressively towards two males having sex together if they don’t want those males to form bonds. Generally, the more two males have sex with each other, the stronger the bond is between them. Since capuchin males do a lot of intergroup fighting (like humans), these bonds are absolutely essential for a male’s survival and reproductive ability. Males that have stronger bonds with strong mates survive longer than those without. When individuals try to overthrow the alpha, those who have strong alliances do a much better job at succeeding than those trying without support from other males.
Because these male-male bonds are so important, there is a lot of male-male sexual behavior in general. Adult males don’t always have sex with the individuals that will be most beneficial to them. In one of our groups an adult male, Pitufo, developed quite the crush on a younger male named Thoreau. As Thoreau was young, low-ranking, and would be emigrating from the group, there was no benefit to Pitufo in forming this bond. This bond might’ve helped Thoreau had Pitufo been nearby when he was attacked by a boa. By the time Pitufo arrived on the scene, it was too late and, although Pitufo fought off the snake the best he could, Thoreau died and Pitufo went quite crazy with grief, acting even more upset and angry than Thoreau’s father. These non-beneficial male-male relationships appear to have developed as a side effect from a selection towards increased male-male sexual activity in general.
In humans, similar activity has been observed with several cultures which had ritualized male-male sexuality that was associated with warriors. In parts of Europe, Japan, and Malasia, male-male sexual activity was part of the warrior cult and helped promote greater male cohesion during conflict. Selective pressure on male bonding in both humans and non-human primates could very easily result in individuals who engage in male-male sex for the majority of their sexual pairings.
Like capuchins, bonobos also engage in homosexual behavior in order to form friendships and increase bonds, although, as most groups consist of male kin living with male kin, their homosexual behavior tends to involve more females. Humans live and work in groups where both males and females are forced to work with and rely on non-kin (more than any other primate species), so increased bonding on both sexes would be very helpful.
Among chimps, there isn’t such a need for the bonds to take place. Chimps live in small groups where the males are all closely related and the females forage in such an environment that forming bonds with other females is more costly than beneficial. However, we do observe homosexual behavior in chimps, even to the point where there is a recorded instance of a female chimp who only showed sexual interest in the other females and never permitted a male to mate with her. The mechanisms of why this would develop in chimps has not been fully answered and it may have remained because of evolutionary history. That is, homosexual behavior may have been beneficial in the past and hasn’t yet been selected against because it isn’t deleterious enough for the species to be removed.
Although humans are less kin-selected than a lot of species (a lot of insect societies have individuals committing suicide for the good of the group), we still exhibit a surprising amount of behaviors that suggest there still remains evolutionary pressures to put the group ahead of the individual at times. Although group selection is a relatively weak force, it can be really influential, especially for primates which live in large groups and have intense social bonds. We send our children off to war, to religious institutions, and humans are known to devote their lives to causes which result in no offspring for themselves. Contrary to being evolutionary puzzles, these behaviors make sense when you consider the net benefit to a culture which enables that culture to overtake over ones. For example, when Christianity was trying to spread through pagan Rome, the practice of Christians caring for individuals who were sick with the plague resulted in more individual Christians dying for the sake of the group, but in the increased spread of the group itself. This behavior isn’t contrary to evolution at all. It’s simply contrary to an incomplete idea of what evolution is and how it works. Too much selfish behavior and the group breaks down and no one benefits. Most supposedly selfless, non-reproductive behaviors can be evolutionarily explained.