Lethal genes evolve simply because of random deleterious mutations and absence of strong selection.
Recessive lethal genes
Random mutations can make a gene product non-functional or reduce its activity. However, in diploid organisms the other fully-functional copy of the gene can compensate for the non-functional allele.
Sometimes both the alleles can carry different mutations which can lead to complementation; this would not affect the gene activity. Also see: Explain allelic complementation at molecular level. Let's not consider this case here.
So, the fitness of the heterozygotes would not be affected and they will continue to propagate. However, if both the alleles are affected then it would lead to lethality (or lets say reduced fitness). This can happen if two heterozygotes (with the same deleterious mutation) mate and give rise to a homozygote (with both the alleles affected). Since siblings (or other close kins) are genetically related, there is a good likelihood that both of them may be carrying a copy of a non-functional allele and homozygous offspring born out of such a mating may have reduced fitness.
Dominant lethal genes
There are some cases of dominant lethal alleles. Examples include the mutated genes responsible for Huntington's disease (or similar poly-Q disorders). Other examples include a mutant allele of a proto-oncogene that leads to its hyperactivity (and therefore cancer).
Dominant lethal alleles persist in the population primarily because of their late onset. In such cases an individual with such an allele would have already mated and produced offspring before the disease kills them.
Other reasons for the persistence of lethal genes
Another possibility (applicable to the case of cancer) is that the mutations are not in the germ cells and were acquired by somatic cells because of some external agent. These mutations would not be transmitted to the next generation.
Sometimes, the deleterious nature of the allele can exert its effect only under certain conditions. Let's say someone has a mutation that causes reduced immunity. Such a person would survive well if they remain in a sterile environment. In general, we can say that there is no strong selective pressure against the mutation.
Sometimes the reduced fitness because of a mutation under a certain condition can be overwhelmed by an increased fitness caused by it under some other condition. A very well known example is that of the haemoglobin allele that causes sickle-cell anaemia. However, the RBCs in the individuals affected by this disease are resistant to infection by the malarial parasite. The mortality due to malaria is much higher than that due to sickle cell anaemia. Therefore, in regions where malaria has high incidence (like Africa) this allele is positively selected.