This is all to do with genetics. Your DNA is made up of different genes which determine things like hair and eye colour. Genes come in different forms called alleles which can be either dominant or recessive. Dominant genes always show up, even if the person only has 1 copy. A recessive allele only shows up if the person gets 2 copies (1 from their mum and 1 from their dad).
So in your example for a child to get ginger hair from their parents, both parents must have 1 copy of the recessive ginger hair allele. This means they are classed as carriers for that gene. It doesn’t show up in parents as they have a dominant allele for another colour (like brown or blonde). But if both parents pass on the recessive ginger allele to their child then they will have 2 copies and the ginger hair colour will show up. There is a 1 in 4 chance this will happen. There is also a 1 in 4 chance the child will get the 2 dominant alleles and a 2 in 4 chance they will become carriers themselves.