Currently, the crown passes to the next in line. So, for example, if Charles were gay and had no legitimate children, the crown would pass to Andrew, and so on.
Historically, gay monarchs like James I married women to produce heirs, then quietly carried on with affairs behind the scenes (often with beautiful young male favourites at court). The line of succession had to be preserved, regardless of their actual preferences.
My hope is that we reach a point where children born through surrogacy and adoption, or even illegitimate children, are recognised equally in matters of inheritance. For that to happen, there would need to be major reforms in inheritance law to reflect the realities of modern families.
Such a change would affect the aristocracy quite significantly. Currently, even when the monarchy allows equal primogeniture (eldest child inherits regardless of gender), this doesn’t extend to titles like Duchies, Earldoms, etc. Many of those still follow strict male-preference inheritance.
It’s time we started thinking seriously about how the law can evolve to recognise all children — not just those “born of the body.