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.