So what principles should be used to determine if a law should be applied to whom and when?
Here (I added the bold and the parts that are in parentheses):
Justice requires that equals be treated equally and unequals unequally. Discrimination is a distinction or the differential treatment based on such a distinction. Whether discrimination is justified depends on the answer to what Aristotle calls "the difficult question": equals and unequals in what? Unjust discrimination either fails to ask the right question or fails to act on the right answer.
(for example a law abiding citizen is not equal to a law breaking citizen and the law recognized the inequality by imprisoning the one but not the other)
In contemporary political discourse the term discrimination itself has come to signify injustice. While this reflects the truth that all human beings have equal dignity simply in virtue of belonging to the human species, it can obscure the fact that human dignity also requires recognition of the truth that, though equal, not everyone is the same (like the guilty prisoner and the innocent free man).
To deny driving licenses to the blind does not assume that they do not deserve equal respect and consideration as persons, but that they are different from other persons in respects relevant to driving.
Some countries have introduced, and others are considering, the extension of the legal recognition and social benefits of marriage to persons in homosexual relationships, in order to "put an end to discrimination".
Are homosexual relationships equal to marital relationships?
The first and most ambitious argument from discrimination proposes that homosexual relationships are equal to marital relationships in those respects that justify the privileged treatment of marriage.
Exclusivity, dependence, duration and sexual nature are not the relevant aspects why marriage is privileged by the State. They are only the conditions of those aspects that make marriage unique:
the vital function of procreation and the socializing functions of bridging the male-female divide and raising children.
When the State uniquely privileges marriage it takes the position that it is in the best interest of society for children to be born and raised in a community where they experience the cause of their biological and historical identity as a loving union preserved by each parent placing the needs of others over their own. By promoting marriage to be the exclusive union between one man and one woman, the State not only protects the rights of children but encourages the values of commitment, restraint and diversity that are needed to preserve community at large.
One objection to this is that not all marriages lead to children. Of course, the State cannot anticipate whether or not couples will have children, but it is clear that only one man and one woman together can be the biological parents of a child and can raise it with the complementarity of motherly and fatherly love. Marital acts are procreative in character, even if non-behavioural conditions do not allow for conception.
The other objection is that marriages fail, to the detriment of children, spouses and families at large. But if individual marriages are in crisis, the correct inference cannot be that social policy should institutionalize this failure rather than counteract it. Through marital benefits the State promotes rather than rewards ideal conditions for procreation and socialization.
Are legal recognition and governmental support justifiable?
When the State uniquely privileges marriage, homosexual relationships are in no way singled out for "unequal treatment".
There are any number of relationships that do not qualify for the benefits of marriage. The question then is why homosexual relationships should be treated as uniquely analogous to marriage.
The aspect that differentiates homosexual unions from other non-marital relationships of dependence and duration is their particular sexual nature, and it is not clear why this should single them out for governmental support. Preferential treatment of this sort would discriminate against all those in dependent relationships of a non-sexual nature: an unmarried woman who cares for her aging mother or two widowed sisters who share a household could not claim privileges and protection from the State.
In France the perception of this problem has led to a more liberal model of civil unions, open to any two citizens. Even this model discriminates against some, as it provides no justification why groups or singles should be financially and socially disadvantaged.
http://www.ewtn.com/library/ISSUES/MARRDISC.HTM