Although there is a lot of speculation, we will never know for sure. What evidence there is, is pure speculation, but it does make a decent circumstantial case:
I think this is a good setup:
The second major implication of the sodomy case is, of course, the
question of Leonardo's sexuality. Homosexuality was common in
quatrocento Florence, and several things indicate that Leonardo was
probably gay. He never married or showed any (recorded) interest in
women; indeed, he wrote in his notebooks that male-female intercourse
disgusted him. His anatomical drawings naturally include the sexual
organs of both genders, but those of the male exhibit much more
extensive attention. Finally, Leonardo surrounded himself with
beautiful young male assistants, such as Salai and Melzi.
The sodomy case does not appear to be disputed, but why Leonardo was arrested for it is. Perhaps it was as much about politics as it was about his sexuality.
Freud also believed Da Vinci was homosexual, and although he tended to think every man and woman had an obsession with phallic objects, it is worth reading some of his reasoning.
The situation contained in the phantasy, that a vulture opened the
mouth of the child and forcefully belabored it with its tail,
corresponds to the idea of fellatio, a sexual act in which the member
is placed into the mouth of the other person. Strangely enough this
phantasy is altogether of a passive character; it resembles certain
dreams and phantasies of women and of passive homosexuals who play the
feminine part in sexual relations.