8 Then God said to Noah and to his sons with him: 9 “I now establish my covenant with you and with your descendants after you 10 and with every living creature that was with you—the birds, the livestock and all the wild animals, all those that came out of the ark with you—every living creature on earth. 11 I establish my covenant with you: Never again will all life be destroyed by the waters of a flood; never again will there be a flood to destroy the earth.”It seems that God has a poor memory, so he needs to do something to remind himself not to do another flood, just like someone with mild dementia posting notes to self on the fridge. As we noted before, there is still wickedness -- the flood didn't actually cure that problem. So maybe that's why God doesn't want to do it again, because it didn't work.
12 And God said, “This is the sign of the covenant I am making between me and you and every living creature with you, a covenant for all generations to come: 13 I have set my rainbow in the clouds, and it will be the sign of the covenant between me and the earth. 14 Whenever I bring clouds over the earth and the rainbow appears in the clouds, 15 I will remember my covenant between me and you and all living creatures of every kind. Never again will the waters become a flood to destroy all life. 16 Whenever the rainbow appears in the clouds, I will see it and remember the everlasting covenant between God and all living creatures of every kind on the earth.”
17 So God said to Noah, “This is the sign of the covenant I have established between me and all life on the earth.”
In any case, as we know thanks to Isaac Newton's exploration of the refraction of light, rainbows are caused by light being reflected and refracted inside water droplets. We can create small rainbows with the spray of a garden hose, and they may also be seen in the spray from waterfalls. As Newton discovered, light of differing wavelengths is refracted at slightly different angles, resulting in white light being decomposed into constituent wavelengths, which humans perceive as different colors. There were rainbows for billions of years before humans existed, and will be after we are gone.