Here’s an example of a legal right, and a justification for its existence:
Society needs someone appointed to make decisions on everyone’s behalf, because we can’t get anything done if we need to consult the whole population about every decision. Since this person is making decisions for everyone, everyone should have a say in choosing who this person is. Therefore, everyone should have a right to vote.
We start with a societal need, and the rights endowed upon citizens are based on that need.
Here’s another societal need:
Society needs good future citizens. Thus, society needs children, and needs to promote the best upbringing for those children. Children require a mother and father. The best care for children is usually given by their parents, and this care will take many years and require huge investment. Thus the people involved need to feel secure as they invest time, effort and money into creating a family in which children can grow up. Thus, we create a legal framework where any man and woman (the most basic and universal requirement for parents) may enter into a legal contract that encourages them to invest in creating a potential home for children. Thus, any pair of one man and one woman may choose to get married.
From the state’s perspective, that’s pretty much it. That’s the legal justification for the existence of a marriage contract. The state needs kids, and kids need parents, and parents need legal protection as they invest in the kids.
Of course, there are plenty of ancillary benefits to marriage. But those are not relevant to the legal existence of marriage.
There’s also nothing in that description about love. Or attraction. Or sexual orientation. Because in terms of marriage as a legal institution, those things are also meaningless. There is no legal basis for a “celebration of love”, but there is a legal basis for providing a framework in which children can be created and raised.
Having a right does not mean that you have to execute that right, just that you have the option. Anyone also has the option not to get married.
Note: As this post discusses the legal justification for marriage, I am of course referring solely to the legal aspects of civil marriage. Religious justifications for marriage are better discussed independently of secular legal questions.