I hope one of the scientists here will correct me if I'm wrong, but I believe it is not well understood by science how instincts are encoded in DNA. But some genetic mutation probably started this instinct.
Well, you are nearly right.
The brain is the centre of instincts and brain development is encoded for in DNA.
It could be understood better, of course, which is why scientists are still trying to research ethology/genetics.