Question: why do mitochondria and chloroplasts contain dna?
Answer: According to the endosymbiosis theory, Mitochondria and chloroplasts were once organisms (bacteria) of their own that got engulfed by another cell and somehow engaged in a symbyiotic (mutualistic) relationship with each other. That is why they have DNA, because they were once distinct organisms.