In 1978, the artist "Gilbert Baker, an openly gay man, and a drag queen, designed the first rainbow flag." "Baker decided to make that symbol a flag because he saw flags as the most powerful symbol of pride. As he later said in an interview, “Our job as gay people was to come out, to be visible, to live in the truth, as I say, to get out of the lie. A flag really fit that mission, because that’s a way of proclaiming your visibility or saying, ‘This is who I am!’” Baker saw the rainbow as a natural flag from the sky, so he adopted eight colors for the stripes, each color with its own meaning (hot pink for sex, red for life, orange for healing, yellow for sunlight, green for nature, turquoise for art, indigo for harmony, and violet for spirit)."
Read more on Britannica.