They gain their legitimacy from having been approved and adopted by the nations of the world. First, rights are considered inherent in us as humans. Therefore, they are inalienable. States may disrespect or violate rights, but they can neither grant them nor take them away in any fundamental sense. Rights are universal, applying to all people in all places at all times.
Rights represent entitlement and claims by individuals.
In response, states have duties to respect and realize rights. Rights are intended to trump over other social goods. Some rights, such as the right not to be tortured, or to be enslaved, cannot be legitimately violated for any reason. Most rights, however, can be legitimately limited under some circumstance, such as the need to interfere with freedom of movement when instituting quarantine or isolation for serious communicable disease. And finally, rights have been created by people and do not derive their legitimacy from religious sources.